From: ewade at vlender dot com
Operating system: GNU/Linux
PHP version: 4.3.7
PHP Bug Type: Sockets related
Bug description: fread appears to drop the buffer
Description:
------------
This function works fine with with PHP-4.3.1 but since recently upgrading
to 4.3.6 and/or 4.3.7 it strips out the headers as appopriate but returns
an empty body. (I've cut out the host code and the cookie code for
obvious security issues.)
What's weird is if I do not strip out the headers they list the correct
Content-Length for the body, but the body is empty.
At first I thought it might be the cURL library so I downgraded from
cURL-7.11.1 to cURL-7.10.3, but that did not resolve the issue. It will
only work with PHP-4.3.1 which seems rather odd. Any thoughts are greatly
appreciated in resolving this issue.
############## ./configure --with apxs=/usr/local/apache/bin/apxs
--enable-bcmath --with-curl --with-mysql=/usr/local/mysql
--with-mcrypt=/usr/local/lib --with-openssl=/usr/local/ssl --without-pear
--disable-cgi --with-gd --with-zlib --with-jpeg-dir=/usr/local/lib
--with-pfpro --enable-xml
Reproduce code:
---------------
function send_to_factual_data($post_data)
{
// Open an SSL connection to the server
$fp = fsockopen("ssl://priate.ssl.host", 443, $errno, $errstr);
// Make sure we're connected
if (!$fp)
return "Error Connecting To FactualData.com - $errstr ($errno)";
else
{
// Send the HTTP headers
fputs($fp, "POST /applet/path/here HTTP/1.0\r\n" .
"User-Agent: Mozilla/4.00\r\n" .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($post_data) . "\r\n" .
"Cookie: CERT=*CENSORED*;\r\n\r\n");
// Send the POST data
fputs($fp, $post_data);
// Read the response - limit of 1M bytes should be OK
$xml = @ fread($fp, 1000000);
// Length of server response including headers
$len = strlen($xml);
// Strip the headers
$xml = strstr($xml, "\r\n\r\n");
// Skip the 2 CRLFs if we removed the headers
if ($len != strlen($xml))
$xml = substr($xml, 4);
return $xml;
}
} // end of function: send_to_factual_data
Expected result:
----------------
When I run the code I expect to have an XML credit report file returned to
me. I expect the code to strip off the HTML headers and leave the body
intact for me to parse with my XML parsing scripts.
Instead what happens is I get back the HTML headers that say they have
content, but there is no content to be found.
Actual result:
--------------
HTTP/1.1 200 OK
Content-Type: text/xml
Content-Length: 57717
Connection: close
Date: Mon, 07 Jun 2004 18:51:24 GMT
Server: Apache Tomcat/4.1.27-LE-jdk14 (HTTP/1.1 Connector)
### The Content-Type and Content-Length are correct, but there is no data
to be found, just the headers.
Thank you for your time!
--
Edit bug report at http://bugs.php.net/?id=28682&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28682&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28682&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28682&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28682&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28682&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28682&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28682&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28682&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28682&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28682&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28682&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28682&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28682&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28682&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28682&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28682&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28682&r=float