If you’re having problems with Drupal cron — like cron runs are timing out or running out of memory — here’s a quick hack to figure out which module is causing the problems.
Edit the includes/module.inc file, and find the function module_invoke_all. Insert the line indicated below to have a notice added to the logs (admin/logs/watchdog) for each module cron is running. You can then figure out the last module running when the problems occur.
foreach (module_implements($hook) as $module) {
$function = $module .'_'. $hook;
if ($hook == 'cron') watchdog('cron', "hit $module cron"); // add this line
...
}
Thanks to Peter Lindstrom for the tip.
—
UPDATE:
The Drupal cron job crashes but I keep getting this error in the watchdog logs: “Attempting to re-run cron while it is already running.”
Then it gets killed after an hour with this message: “Cron has been running for more than an hour and is most likely stuck.”
To force Drupal to allow cron jobs to run again, you have to:
- Delete the “cron_semaphore” variable from the database. (Hat tip to cyberswat on drupal.org.)
- Clear the Drupal cache to reload the variables. (Install the Devel module and go to example.com/devel/cache/clear to clear the cache quickly.)
There’s a Drupal variable that is created when cron starts, and is supposed to get deleted when cron ends. If the cron job crashes, the variable is left behind and no new cron jobs can run until the variable gets policed up in an hour.
To clear the cron lock, delete the “cron_semaphore” variable in your database.
mysql> select * from variable where name = 'cron_semaphore'; +----------------+---------------+ | name | value | +----------------+---------------+ | cron_semaphore | i:1246773950; | +----------------+---------------+ 1 row in set (0.00 sec) mysql> delete from variable where name = 'cron_semaphore'; Query OK, 1 row affected (0.00 sec)
Hi, I'm Greg. I'm a cofounder of Killer Aces Media. We publish community blogs like 