#32532 [Opn->Bgs]: fgets() fread() stream_get_content() functions return junk

From: Date: Fri, 01 Apr 2005 21:06:42 +0000
Subject: #32532 [Opn->Bgs]: fgets() fread() stream_get_content() functions return junk
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-76180@lists.php.net to get a copy of this message
 ID:               32532
 Updated by:       wez@php.net
 Reported By:      destroyer at balticum-tv dot lt
-Status:           Open
+Status:           Bogus
 Bug Type:         Sockets related
 Operating System: Win32 / Linux
 PHP Version:      5CVS-2005-04-01 (dev)
 New Comment:

Read the HTTP 1.1 spec.
You've just discovered chunked encoding.


Previous Comments:
------------------------------------------------------------------------

[2005-04-01 16:08:07] 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 15:31:22] 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 14:22:55] destroyer at balticum-tv dot lt

It seems that it still returns not only 2000, but also other text.

------------------------------------------------------------------------

[2005-04-01 14:14:00] 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>


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=32532&edit=1


Thread (5 messages)

« previous php.bugs (#76180) next »