#25568 [Fbk->NoF]: feof is not working correctly with fsockopen
ID: 25568
Updated by: sniper@php.net
Reported By: svan at mailgate dot ru
-Status: Feedback
+Status: No Feedback
Bug Type: Filesystem function related
Operating System: Linux
PHP Version: 4.3.3
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2003-09-24 18:39:25] iliaa@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
------------------------------------------------------------------------
[2003-09-18 01:28:40] svan at mailgate dot ru
No errors. error_reporting is set to E_ALL
------------------------------------------------------------------------
[2003-09-17 19:38:15] sniper@php.net
Do you get any errors? (make sure error_reporting is set to E_ALL and
nothing else)
------------------------------------------------------------------------
[2003-09-17 02:38:00] 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 02:33:41] 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"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25568&edit=1
Thread (6 messages)