I want to write a php script that keeps the apache_log file open and “listen” to the log and deal with each log entry as it happens.
I’m thinking that I need to open a file, get the number of lines, then do this again in a loop – and when the size is different, read the new lines and process them.
Am I barking up the wrong tree, or is there a silly easy solution that I have missed?
Chris
The quick-and-dirty way would be to use
tail -fsomehow (assuming it’s available):You could pipe the output in to PHP:
tail -f file | php myscript.php, and then read fromphp://stdin.Or, you could use
popenin the script itself: