Re-running a script once a minute

I have a simple script to read and echo a text file and close the file. The file is constantly being edited, so I want to re-run the script once a minute. I know I did this some time ago but I’m 84 and don’t remember how I did it. LOL

Found the answer
header(“refresh: 30”);

Here’s a simple example:

<?php
// Set the page to refresh every 60 seconds
header("refresh: 60");

// lets say your file is named "data.txt"
$filename = "data.txt";

// Check if the file exists
if (file_exists($filename)) {
    // Read and display the file content
    $content = file_get_contents($filename);
    echo nl2br($content); // nl2br() will convert new lines in the text file to <br> in HTML
} else {
    echo "File not found!";
}
?>

or you can use HTML

<meta http-equiv="refresh" content="60">

Refreshing the page once a minute is not a good idea. Use Firebase real-time database instead. It automatically changes on the page when the data changes.

Sorry, but in this case that would be using a sledge hammer to drive a nail. I’m not talking about a data base but just a text file of less than thirty lines.

Sponsor our Newsletter | Privacy Policy | Terms of Service