php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25568 feof is not working correctly with fsockopen
Submitted: 2003-09-17 02:33 UTC Modified: 2003-09-29 05:57 UTC
Votes:4
Avg. Score:3.5 ± 0.9
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: svan at mailgate dot ru Assigned:
Status: No Feedback Package: Filesystem function related
PHP Version: 4.3.3 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: svan at mailgate dot ru
New email:
PHP Version: OS:

 

 [2003-09-17 02:33 UTC] svan at mailgate dot ru
Description:
------------
End of file is not detect coorectly when stream open with fsockopen(). When I read binary data from such stream the end of file detected absolutely unexpected and before real end.

Reproduce code:
---------------
	$fp = fsockopen("www.xxxxxxxxxx.xx", 80, $errno, $errstr, 30);
	if(!$fp)
	   exit;
	fputs($fp, "GET http://www.xxxxxxxxxx.xx/CENTER.GIF HTTP/1.0\n\n");
	$qStr = "";
	while(($tmpStr = fgets($fp, 255))) 
           if($tmpStr == "\r\n") break;
           else if( !strncmp($tmpStr, "Content-Length:", strlen("Content-Length:")) ) $len = (int)substr($tmpStr, strlen("Content-Length:"));
	$qStr=fread($fp, $len);
	fclose($fp);
=========================== OR ==============
$fp = fsockopen("www.xxxxxxxxxx.xx", 80, $errno, $errstr, 30);
	if(!$fp) exit;
	fputs($fp, "GET http://www.xxxxxxxxxx.xx/CENTER.GIF HTTP/1.0\n\n");
	$qStr = "";
	while(($tmpStr = fgets($fp, 255))) if($tmpStr == "\r\n") break;
        while( !feof( $fp ) $qStr .= fread($fp, 1);
	fclose($fp);


Expected result:
----------------
$qStr contain full content of "CENTER.GIF"

Actual result:
--------------
$qStr contain cutted content of "CENTER.GIF"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-17 02:38 UTC] svan at mailgate dot ru
Possible workaround:
	$fp = fsockopen("www.xxxxxxxxxx.xx", 80, $errno, $errstr, 30);
	if(!$fp)
	   exit;
	fputs($fp, "GET http://www.xxxxxxxxxx.xx/CENTER.GIF HTTP/1.0\n\n");
	$qStr = "";
	while(($tmpStr = fgets($fp, 255))) 
           if($tmpStr == "\r\n") break;
           else if( !strncmp($tmpStr, "Content-Length:",
strlen("Content-Length:")) ) $len = (int)substr($tmpStr,
strlen("Content-Length:"));
	while( true  ){
		$rrr = stream_get_meta_data( $fp );
		if( $rrr['eof'] == 1 ) break;
		$qStr.=fread($fp, $len);
		if( strlen( $qStr ) >= $len ) break;
	}
	fclose($fp);
 [2003-09-17 19:38 UTC] sniper@php.net
Do you get any errors? (make sure error_reporting is set to E_ALL and nothing else)

 [2003-09-18 01:28 UTC] svan at mailgate dot ru
No errors. error_reporting is set to E_ALL
 [2003-09-29 05:57 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 17:01:29 2024 UTC