The following is a tutorial specifically about feof, including implementation.
The following is a tutorial specifically about feof, including implementation.
feof
(PHP 4, PHP 5)
feof - the file pointer to the end of the test file
Description
boolean feof(resource$handle)
Pointer to the archive file at the end of the test.
Parameters
Handle
The file pointer must be valid and must point to a file successfully opened by fopen() or fsockopen() (and not yet closed by fclose()).
Return value
Returns TRUE if the file pointer is EOF analyzed or an error occurred (including socket timeout), otherwise returns FALSE.
Note
Warning
If a connection opened by fsockopen() does not close the server, feof() will wait until the timeout has been reached and return the value TRUE. The default timeout value is 60 seconds. You can use stream_set_timeout() to change this value.
Warning
If the file pointer passed is invalid, you will get an infinite loop because feof() does not return TRUE.
Look at the example:
// if file can not be read or doesn't exist fopen function returns FALSE
$file = @fopen("no_such_file", "r");
// FALSE from fopen will issue warning and result in infinite loop here
while (!feof($file)) {
}
fclose($file);
?>