|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30649 Invalid content with HTTP response > 8000 bytes
Submitted: 2004-11-01 13:57 UTC Modified: 2004-11-01 14:00 UTC
From: l dot zurschmiede at delightsoftware dot com Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5.0.2 OS: Linux 2.6.7
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: l dot zurschmiede at delightsoftware dot com
New email:
PHP Version: OS:


 [2004-11-01 13:57 UTC] l dot zurschmiede at delightsoftware dot com
When a Socket/Stream function is used to get content,  
bigger then 8000bytes from a HTTP-Server, the received  
content has a false begin (3bb4 or similar) and end  
This failure occures only if the Server does not respond  
with a "Content-Length: xx" header AND a clientside  
protocol of HTTP/1.1.  
If the clientside protocol is invalid (like "HTTP 1.1" or  
"HTTP 1.0") or it's an old one like HTTP/1.0, there is no  
failure. It only occures with HTTP/1.1 and NO serverside  
"Content-Length" header.  
The example-Script is a Server and a Client-Script. The  
Server-Script sends exactly 8001 bytes as content to the  
Client-Script. Comment out the "Content-Length" in Server,  
or the additional $cont .= "."; to retrieve the valid  
(Tested on PHP-5.0.2 with Apache 2.0.50, glibc-2.3.2) 
(A similarly one seams to be #28955) 

Reproduce code:
Client test_client.php:
$cont = '';
$head = '';
$fp = stream_socket_client('tcp://localhost:80', $errno, $error, 30);
fputs($fp, "POST /test_server.php HTTP/1.1\r\nHost: localhost\r\n");
fputs($fp, "Connection: Close\r\nAccept: text/xml\r\n\r\n");
while ( $str = trim(fgets($fp, 2048)) )
  $head .= $str;
while ( !(feof($fp)) )
  $cont .= fgets($fp, 2048);
print("Length: ".strlen($cont)."<br/>\r\nbegin (10): ".substr($cont, 0, 10)." <br/>\r\nend (10): ".substr($cont, (strlen($cont) - 10)));

Server test_server.php:
$cont = '';
for ($i = 0; $i < 80; $i++)
  $cont .= '....................................................................................................';
$cont .= '.';
header('Content-Type: text/plain; charset=\"utf-8\"');
//header('Content-Length: '.strlen($cont));

Expected result:
Length: 8001<br/> 
begin (10): .......... <br/> 
end (10): .......... 

Actual result:
Length: 8014<br/> 
begin (10): 1f41 
.... <br/> 
end (10): ... 
There is no exception visible in a backtrace. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-01 14:00 UTC]
This is not a bug, this is called "Chunked Encoding". See the HTTP RFCs for more information.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Apr 09 21:01:23 2020 UTC