From: svan at mailgate dot ru
Operating system: Linux
PHP version: 4.3.3
PHP Bug Type: Filesystem function related
Bug description: feof is not working correctly with fsockopen
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 bug report at http://bugs.php.net/?id=25568&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=25568&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=25568&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=25568&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=25568&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=25568&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=25568&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=25568&r=support
Expected behavior: http://bugs.php.net/fix.php?id=25568&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=25568&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=25568&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=25568&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=25568&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=25568&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=25568&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=25568&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=25568&r=float