What is the best practice for ensuring a PHP script only runs once per day?

To ensure a PHP script only runs once per day, you can use a combination of a timestamp stored in a file or database and the current date to check if the script has already run today. If the script has not run yet, update the timestamp to the current date after it completes.

$filename = 'lastrun.txt';
$lastrun = file_get_contents($filename);

if ($lastrun != date('Y-m-d')) {
    // Run your script here

    // Update the last run timestamp
    file_put_contents($filename, date('Y-m-d'));
}