search for in the  
<fclosefflush>
Last updated: Thu, 19 May 2005

feof

(PHP 3, PHP 4, PHP 5)

feof -- Tests for end-of-file on a file pointer

Description

bool feof ( resource handle )

Returns TRUE if the file pointer is at EOF or an error occurs (including socket timeout); otherwise returns FALSE.

Warning

If a connection opened by fsockopen() wasn't closed by the server, feof() will wait until a timeout has been reached to return TRUE. The default timeout value is 60 seconds. You may use stream_set_timeout() to change this value.

The file pointer must be valid, and must point to a file successfully opened by fopen() or fsockopen().



User Contributed Notes
feof
04-Mar-2005 11:02
if you're worried the file pointer is invalid, TEST IT before you go into your loop... that way it'll never be an infinite loop.
bruno dot moreira at brturbo dot com
12-Jan-2005 05:43
Use it with many caution. If your php.ini don't stop the script when it enter a infinity loop.
I don't think as good the use of feof with an while loop.
See the example:
$a=open("/etc/passwd");
while(!feof($a)){
 echo fgets($a);
 }
I used '/etc/passwd' because obviously the apache user isn't root, then cannot read '/etc/passwd'.
If in future the feof return's some different that TRUE or FALSE, this can be used with good results.
mark at newfangled dot com
04-May-2004 12:39
When a fopen() is done on a file that has permissions that are set to
not allow the current process user to read it or the file doesn't exist
it returns false. This is expected. The problem is when feof() is fed
the invalid handle it doesn't return TRUE() thus creating an infinite
loop in the following code example.

<?php
$fp
= fopen( 't.txt', 'r' );

while( !
feof( $fp ) )
{
   print
fgets( $fp );
}

fclose( $fp );
?>

feof() would return TRUE to cancel the loop and the script would end.
There would of course be warnings because of the invalid file handle,
but that is expected.

There should be better error handling on the developers part and catch
the invalid file handle, but I would expect the file functions to handle
this situation accordingly.
Johannes
12-Mar-2004 04:47
I found feof() to be a slow function when using a non-blocking connection.

The function stream_get_meta_data() returns much quicker and has a return field 'eof'.

<fclosefflush>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT