tail - alike weirdness in php

Top Page
Author: Bopolissimus Platypus
Date:  
To: PHP Web Development
Subject: tail - alike weirdness in php
hello all,

i ran across something weird when i was writing something that sits on a
file and sort of works like "tail -f".

when you do something like this:

while(!feof($fp))
{
     $line=fgets($fp);
}


when you get to the end of the loop, feof($fp) is true.
now, if the file is being updated (e.g., it's a log file)
then the file might not actually be at end of file anymore.
however, your $fp filehandle still thinks that it is (at eof).

in C, you would call clearerr(FILE *) to clear the
eof flag. there doesn't seem to be anything similar
in PHP. has anyone come across something like
this?

finally, what i had to do was:

$pos=ftell($fp);
$pos--;
if($pos>=0)
fgetc($fp);

and that clears the eof flag.

tiger

--
Gerald Timothy Quimpo gquimpo*hotmail.com tiger*sni*ph
http://bopolissimus.sni.ph
Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78"

    In necessariis unitas, in dubiis, libertas, 
     in omnibus caritas


______________________________________________
PHP Web Development Mailing List
php@??? (#PHP @ irc.free.net.ph)
http://lists.free.net.ph/mailman/listinfo/php
Searchable Archives: http://marc.free.net.ph