|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28682 fread appears to drop the buffer
Submitted: 2004-06-07 20:54 UTC Modified: 2004-06-09 16:25 UTC
From: ewade at vlender dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 4.3.7 OS: GNU/Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: ewade at vlender dot com
New email:
PHP Version: OS:


 [2004-06-07 20:54 UTC] ewade at vlender dot com
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://", 443, $errno, $errstr);

    // Make sure we're connected
    if (!$fp)
        return "Error Connecting To - $errstr ($errno)";
        // 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!


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-09 16:25 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

You should never rely on single fread() to read all 
available data especially when dealing with remote servers. 
Replace your code with: 
$xml = ''; 
while (($line = fread($fp, 1000000)))) { 
	$xml .= $line; 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Jan 29 00:03:33 2022 UTC