I have a cron function that is being triggered but not completing. The function is supposed to run only once on the first of every month. The function runs but, I think, gets as far as comparing the $summary_sent variable and then stops. Cron is running once every 3 hours.
By changing the $day_of_month_to_run to the current day and resetting the $summary_sent variable I can successfully run the full function using cron but, when left to run automatically on the first of the month it fails.
variable_set('summary_email_recipients', '[email protected]');
function appointments_cron() {
send_monthly_summary();
}
function send_monthly_summary() {
$recipients = variable_get(summary_email_recipients);
// run on first of the month
$day_of_month_to_run = 01;
$date_string = date('Y-m-'.$day_of_month_to_run);
// only run on the correct day of the month
if ( date('Y-m-d') == $date_string ) {
// check if the process was last run today
// prevents process being run multiple times on the same day
$summary_sent = variable_get( 'appointment_summary_sent' );
if ($summary_sent != $date_string) {
// do stuff
// set a record of this process
variable_set( 'appointment_summary_sent', $date_string );
}
}
}
Why isn't this running once on the 1st of every month as expected?