From: jon at foneport dot com
Operating system:
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: Documentation for feof seems misleading
Description:
------------
The documentaion for feof function seems contradictory. It seesm to
suggest that the normal behaviour on a socket timeout is to cause feof to
return TRUE and that calling stream_set_timeout() changes the behaviour of
feof to cause it to instead return FALSE on timeout. From useage experience
with various versions of PHP, feof only returns TRUE on a socket if the
connection has closed, whether or not stream_set_timeout() has been called
makes no difference to the behaviour of feof(). This seems sensible as
getting feof to return FALSE on timeout would not help prevent anyone
getting into a long while loop while testing feof. It seems that the way
things actually work are correct whereas the documention is a little
confusing or misleading.
>From the documentation
"Returns TRUE if the file pointer is at EOF or an error occurs (including
socket timeout); otherwise returns FALSE."
"Warning
feof() will return TRUE only if the connection opened by fsockopen() is
closed. This can cause a script to timeout. The workaround for this is to
use stream_set_timeout(), so that feof() will return FALSE on timeout. "
Reproduce code:
---------------
stream_set_timeout($fp, 5);
while(!feof($fp)) { // until connection is closed or timed
$status = socket_get_status($fp);
$data[] = fgets($fp, 1000);
$status = socket_get_status($fp);
}
This will loop until disconnected.
$status['timed_out'] get set to 1 and feof continues to return false. This
occurs whether I set stream_set_timeout or not. The behaviour of feof() is
unchanged.
--
Edit bug report at http://bugs.php.net/?id=29942&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29942&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=29942&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=29942&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=29942&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29942&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29942&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29942&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29942&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29942&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29942&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29942&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29942&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29942&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29942&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29942&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29942&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29942&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29942&r=float