|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2004-09-06 21:48 UTC] nlopess@php.net
  [2020-02-07 06:11 UTC] phpdocbot@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 05:00:02 2025 UTC | 
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.