php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #29942 Documentation for feof seems misleading
Submitted: 2004-09-02 00:45 UTC Modified: 2004-09-06 21:48 UTC
From: jon at foneport dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2004-09-02 00:45 UTC] jon at foneport dot com
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.



Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-06 21:48 UTC] nlopess@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2020-02-07 06:11 UTC] phpdocbot@php.net
Automatic comment on behalf of nlopess
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=3c3746916a33a5f8591f87fc7ce04fc54af7edba
Log: fix #29942: misleading timeout description
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Aug 17 08:01:27 2024 UTC