Re: read the last line in a file?
| From: | Per Jessen | Date: | Sun, 17 May 2009 08:27:24 +0000 |
| Subject: | Re: read the last line in a file? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292696@lists.php.net to get a copy of this message | ||
Tom Worster wrote:
>> 1) the inotify interface will alert you when a file or directory
>> changes.
>
> do you mean the pecl inotify extension?
Not specifically, but if that's how inotify is available in PHP, then
yes.
> that would eliminate the polling and the associated lag. but the php
> manual says it requires linux. if that's the case then it's not going
> to work for me. the app i'm working with runs on os x.
inotify comes with linux, yes.
>> 2) run tail -f logfile | <yourscript> and read from stdin. (not
>> tested).
>
> i thought of this but i couldn't see much difference between reading
> from stdin and opening the log file itself and reading from that
> (reading and tesing for eof periodically in both cases i suppose). but
> i may be missing something in your suggestion.
With the above, your code can just keep reading from stdi, no need to
check for eof etc.
>> 3) if you can change the logfile to a fifo, you're all set.
>
> i don't have any control over the app that writes the log file. if
> there were a utility like tail -f that opens a fifo for output rather
> than outputting to sdtout...
Once piped to your script, reading from stdout will be just like reading
from a fifo.
/Per
--
Per Jessen, Zürich (16.2°C)