Re: read the last line in a file?
| From: | Per Jessen | Date: | Sat, 16 May 2009 07:55:06 +0000 |
| Subject: | Re: read the last line in a file? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-292671@lists.php.net to get a copy of this message | ||
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 | <yourscript> 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)