Re: [PHP] read the last line in a file?
Tom Worster wrote: do you mean the pecl inotify extension? that would eliminate the polling and the associated lag. but the php manual says it requires linux. Yup - and it's kernel, so I don't think it could easily be ported to OS X. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] read the last line in a file?
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 | 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
Re: [PHP] read the last line in a file?
On 5/16/09 3:55 AM, "Per Jessen" wrote: > Tom Worster wrote: > >> imagine writing a script to run as a daemon reading data off the >> bottom of a log file that gets updated every few minutes and >> processing each new log line as they arrive. >> >> i could exec("tail $logfile", $lines, $status) every now and then. or >> poll the file mtime and run exec("tail $logfile", $lines, $status) >> when it changes. there will be some lag due to the polling interval. >> >> but it would be nice to not have to poll the file and somehow trigger >> the processing of the new line when the log file is written. but i'm >> not sure how to do that. >> >> any ideas? > > 1) the inotify interface will alert you when a file or directory > changes. do you mean the pecl inotify extension? 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. os x 10.5 has FSEvents but i'm not sure that's much improvement on polling the log file. > 2) run tail -f logfile | 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. > 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... thanks for the suggestions, per! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] read the last line in a file?
Tom Worster wrote: > imagine writing a script to run as a daemon reading data off the > bottom of a log file that gets updated every few minutes and > processing each new log line as they arrive. > > i could exec("tail $logfile", $lines, $status) every now and then. or > poll the file mtime and run exec("tail $logfile", $lines, $status) > when it changes. there will be some lag due to the polling interval. > > but it would be nice to not have to poll the file and somehow trigger > the processing of the new line when the log file is written. but i'm > not sure how to do that. > > any ideas? 1) the inotify interface will alert you when a file or directory changes. 2) run tail -f logfile | and read from stdin. (not tested). 3) if you can change the logfile to a fifo, you're all set. /Per -- Per Jessen, Zürich (11.7°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] read the last line in a file?
imagine writing a script to run as a daemon reading data off the bottom of a log file that gets updated every few minutes and processing each new log line as they arrive. i could exec("tail $logfile", $lines, $status) every now and then. or poll the file mtime and run exec("tail $logfile", $lines, $status) when it changes. there will be some lag due to the polling interval. but it would be nice to not have to poll the file and somehow trigger the processing of the new line when the log file is written. but i'm not sure how to do that. any ideas? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php