php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32532 fgets() fread() stream_get_content() functions return junk
Submitted: 2005-04-01 14:14 UTC Modified: 2005-04-01 23:06 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: destroyer at balticum-tv dot lt Assigned:
Status: Not a bug Package: Sockets related
PHP Version: 5CVS-2005-04-01 (dev) OS: Win32 / 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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: destroyer at balticum-tv dot lt
New email:
PHP Version: OS:

 

 [2005-04-01 14:14 UTC] destroyer at balticum-tv dot lt
Description:
------------
It seems that all these receive related functions return junk. They just sometimes return 2000.
Before i downloaded a snapshot 5.0.x-dev they were returning not only 2000, but other text such as "10c" "2b3" etc.

Reproduce code:
---------------
$fp = @fsockopen($dom, 80, $errno, $errstr, 30);
stream_set_timeout($fp,20);
...
while (!feof($fp)) {
	$result = fgets($fp, 4096);
	if($result !== FALSE)
		$out .= $result;
}
...
echo $out;

Expected result:
----------------
<HTML>
<BODY>
The test
Other text
</BODY>
</HTML>

Actual result:
--------------
<HTML>
<BODY>
2000
The test
2000
Other text
</BODY>
</HTML>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-01 14:22 UTC] destroyer at balticum-tv dot lt
It seems that it still returns not only 2000, but also other text.
 [2005-04-01 15:31 UTC] sniper@php.net
Can you provide a test script that we can actually run?
(a PHP script starts with <?php and ends with ?> ..)

 [2005-04-01 16:08 UTC] destroyer at balticum-tv dot lt
<?php
	$dom = "www.google.co.uk";
	$fp = @fsockopen($dom, 80, $errno, $errstr, 30);
	$req = "GET /search?hl=en&q=test&btnG=Google+Search&meta= HTTP/1.1\r\n";
	$req .= "Host: $dom\r\n";
	$req .= "Content-Type: application/x-www-form-urlencoded\r\n";
	$req .= "Content-Length: " . strlen($pv) . "\r\n";
	$req .= "Connection: Close\r\n\r\n";
	stream_set_timeout($fp,20);
	fwrite($fp, $req);
	while (!feof($fp)) {
		$result = fgets($fp, 4096);
		if($result !== FALSE)
			$out .= $result;
	}
	fclose($fp);
	echo $out;
?>
 [2005-04-01 23:06 UTC] wez@php.net
Read the HTTP 1.1 spec.
You've just discovered chunked encoding.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 01:01:30 2024 UTC