|
|
 |
feof (PHP 3, PHP 4, PHP 5) feof -- Verifica si el apuntador a un archivo está al final del
archivo Descripciónint feof ( int handle )
Devuelve TRUE si el apuntador del fichero está en EOF o si ocurre
un error (incluyendo tiempo de espera agotado); en otro caso devuelve
FALSE.
| Aviso |
Si una conexión abierta por fsockopen() no
fue cerrada por el servidor, feof() esperará
hasta que ocurra un tiempo de espera agotado para regresar TRUE.
El tiempo de espera por default es 60 segundos. Puede usar
stream_set_timeout() para cambiar este valor.
|
El puntero de fichero debe de ser
valido y debe de apuntar a un fichero abierto con exito por
fopen() o fsockopen().
jorge dot mendes at constante dot pt
07-Jul-2006 09:23
feof() not reliable
I used feof() in a context of retrieving a CSV file into a database.
I had the following code:
while(!feof($file_handler)){
$row = fgets($file_handler);
(...)
}
I was processing several files, and in some of them, the last row was duplicated, so I assume that feof() is not reliable.
That's how I solved the problem:
while($row = fgets($file_handler)){
(...)
}
ironoxid at libero dot it
06-Jun-2006 06:52
I really thought that the feof() was TRUE when the logical file pointer is a EOF.
but no !
we need to read and get an empty record before the eof() reports TRUE.
So
$fp = fopen('test.bin','rb');
while(!feof($fp)) {
$c = fgetc($fp);
// ... do something with $c
echo ftell($fp), ",";
}
echo 'EOF!';
prints for two time the last byte position.
If our file length is 5 byte this code prints
0,1,2,3,4,5,5,EOF!
Because of this, you have to do another check to verify if fgetc really reads another byte (to prevent error on "do something with $c" ^_^).
To prevent errors you have to use this code
$fp = fopen('test.bin','rb');
while(!feof($fp)) {
$c = fgetc($fp);
if($c === false) break;
// ... do something with $c
}
but this is the same of
$fp = fopen('test.bin','rb');
while(($c = fgetc($fp))!==false) {
// ... do something with $c
}
Consequently feof() is simply useless.
Before write this note I want to submit this as a php bug but one php developer said that this does not imply a bug in PHP itself (http://bugs.php.net/bug.php?id=35136&edit=2).
If this is not a bug I think that this need at least to be noticed.
Sorry for my bad english.
Bye ;)
docey
12-Jan-2006 11:07
because using an invalid handle can couse seriuos trouble,
here is some very simple code that can prevent any piece
of code to runaway using an invalid handle.
function is_valid(&$fp, $type){
if(is_resource($fp)){
if(get_resource_type($fp) == $type){
return true;
}else{
return false;
}
}else{
return false;
}
}
now all you need to do to check if you got a valid handle,
if(is_valid($fp, "file")){
// your code
}else{
// your error code
}
its that simple to prevent any of your code from using an
invalid handle. ofcourse you can change the "file" line to
any resource you want to check for invalidies.
please use good coding habits, and don't assume any
varialbles, resource or objects are good. check them!!
01-Jan-2006 06:27
if you use fseek function to pos the pointer exceed the size the file,feof still return true.so note that when you use feof as the condition of while loop.
info at derlange dot tk
06-Aug-2005 03:20
NOTE!
if your file is empty and you make the feof()-check, it will return true the first time you call it.
example:
$handle=fopen("file","r");
while(!feof($handle))
{
$line=fgets($handle);
}
$line is now an empty string ( "" )
you have to check the size of your file before, like this sample code:
if (filesize("file")>0)
{
while( !feof($handle) )
{
$zeile=fgets($handle);
}
}
31-Jul-2005 10:21
if you hit an feof() infinite loop, watch out for resultant humongous logs, they can cripple a site with hard disk usage limits or run up excess usage fees.
04-Mar-2005 09: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 03: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 10: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 02: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'.
| |
|
| Chiste de... Varios | | Marcianos | - Un marciano viscoso se acerca al portero de una discoteca y le dice:
- Vengo de Marte.
- El otro, crecido, le dice: ¿De marte de quién? | | Chistes en tu mail | | ©ContenidosGratis |
| Inicio | Acción | Estrategia | Palabras | Puzzles | Solitarios | Foro Trucos |  | Cake Mania Jugadores: 6835 Categoría del juego: Acción Objetivo del juego: Ayuda a Jill a recuperar la pastelería de su abuela llevando su propia pastelería; consigue clientes y gana dinero. |
|  | Rainbow Web Jugadores: 2199 Categoría del juego: Puzzles Objetivo del juego: Rompe un pegajoso hechizo y salva un reino de fantasía en Rainbow Web. Tendrás toneladas de diversión mientras juegas a este mágico desafío para la mente. |
|  | Mahjongg Fortuna Jugadores: 12462 Categoría del juego: Solitarios Objetivo del juego: Velocidad y habilidad mental son las armas más importantes en esta versión de un antiguo juego asiático. Despeja el tablero lo antes posible haciendo clic en las fichas iguales y gánate la fama eterna de la puntuación más alta. |
|  | Chainz 2 Jugadores: 6955 Categoría del juego: Puzzles Objetivo del juego: Entra en el mundo de las combinaciones con Chainz 2: Relinked, emocionante secuela del exitazo del año pasado, Chainz. Gira eslabones y crea combinaciones de 3 ó más. |
|  | Delicious Jugadores: 4405 Categoría del juego: Acción Objetivo del juego: ¿Eres un as de la multitarea? ¿Quieres que tus clientes estén contentos? ¡Pues Delicious es tu juego! Sacia el apetito de los clientes y tenlos contentos; ¡no te arriesgues! |
|  | Bookworm Jugadores: 4568 Categoría del juego: Palabras Objetivo del juego: Junta las letras para formar palabras. ¡Las palabras más largas valen más puntos! |
|  | Zuma Jugadores: 4976 Categoría del juego: Acción Objetivo del juego: Controla el ídolo de la rana de piedra de los antiguos Zuma en este intrigante enigma de acción. ¡Dispara bolas para formar conjuntos de tres, pero si dejas que lleguen a la calavera dorada morirás! |
|  | Jewel of Atlantis Jugadores: 3798 Categoría del juego: Puzzles Objetivo del juego: Descubre la ciudad hundida de la Atlántida y busca valiosos tesoros. Viaja más allá de las profundidades del mar y vive trepidantes aventuras en Jewel of Atlantis. |
|  | Jewel Quest Jugadores: 3727 Categoría del juego: Puzzles Objetivo del juego: Convierte la arena de la antigua selva en oro tan rápido como puedas juntando grupos de 3 elementos. ¡Los grupos más grandes valen más puntos! |
|  | Bejeweled 2 Jugadores: 3659 Categoría del juego: Puzzles Objetivo del juego: Con cuatro modos de juego únicos y fascinantes, nuevas piezas de juego explosivas e imponentes fondos planetarios, Bejeweled 2 es mucho más adictivo que nunca. |
|
|