After 5 hours of trying I'm coming to you.
I need to create a page, that will automatically update himself and display file content when file changed. Let say we have foo.txt, that's updating continuously. I don't want page to reload every n seconds. Additionally I need only last 30 lines of this file displayed. I came up with this:
<?php //live.php
$handle = popen("tail -30l foo.txt 2>&1", 'r');
while(!feof($handle)) {
$buffer = fgets($handle);
echo "$buffer<br/>\n";
ob_flush();
flush();
}
pclose($handle);
?>
what successfully displays last 30 lines of file, but not updating. That's where I'm stuck - I don't know how to achieve below tasks:
- Check for file update,
- Display live.php when file changes.
Can I use Ajax update feature with this?