0

Script

<?php
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
?>

According to the script this is reading the file untill the end and then it breaks. Is there easy way or function to keep the while function to loop and checking for new lines every 5 seconds after reaches end of file?

UPDATE While googling and checking any related post from stackoverflow I found the answer: How To watch a file write in PHP?

This is what I was looking for.

John
  • 323
  • 1
  • 4
  • 13

1 Answers1

0

Probably a better solution would be to use something like Cron (if you're using Linux) to run your script every 5sec. Cron is an utility for schedule a routine background job at a specific time and/or day on an on-going basis: Linux Crontab: 15 Awesome Cron Job Examples

With that in mind, you would have to change your script for checking if the file has changed: How to check if a file has changed?

  • I plan to run on Windows. – John Apr 17 '19 at 15:18
  • In that case, try to search for equivalent tools: [What is the Windows version of cron? [closed]](https://stackoverflow.com/questions/132971/what-is-the-windows-version-of-cron). – Ana Chiozi Apr 17 '19 at 15:53