Re: read the last line in a file?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux