//--------------------------------------------------------------
// PLACE THIS CODE AT THE TOP OF YOUR SCRIPT
//--------------------------------------------------------------
// This code insures that your script runs *once* a day in the
// hour long window you specifiy.
// IMPORTANT: Change the values of HOURS, MINS and ABS_DIR for your cron script.
// Hour and minute to start the hour-long window for running this script.
// The time is the local time, which will be adjusted for DST.
// (NOTE: Hours run from 0 to 23.)
//
$HOURS = 6;
$MINS = 30;
// Directory location of lock file. This must be a directory in *your* website.
$ABS_DIR="/export/www/PUT-YOUR-SITE-HERE/lock";
// Make sure lock file doesn't exist (insures we run only once a day)
$lock_name = strftime("$ABS_DIR/%Y-%m-%d.mail.php");
clearstatcache();
if (file_exists($lock_name)) {
print "This job has already been run today<br>";
exit;
}
// Run job if we are in the correct time window
$time_array = getdate();
$hours = $time_array["hours"];
$mins = $time_array["minutes"];
if ( ! ($hours==$HOURS and $mins>=$MINS or $hours==($HOURS+1)%24 and $mins<$MINS) ) {
exit;
}
// Create lock file, to prevent this script running again today.
touch($lock_name);
//--------------------------------------------------------------
// YOUR SCRIPT FOLLOWS HERE
//--------------------------------------------------------------