Drupal: Optimization of cron.php
You need to run cron frequently (for example, every 10 minutes). And meet some problems on this way.
Modules launched by cron work with external sites and connection with them can be bad or script is disabled by timeout set in PHP.ini. It’s ok, but cron spoils the whole thing. It implements this operation in an hour and then says that time for routine procedures is more than an hour and the system hangs up. over an hour, most likely the system is hanging up.
Solution
When cron runs, Drupal sets "cron_semaphore" variable to the current time to make sure only one cron is launched in the meantime. You can change 2507 line in /includes/common.inc file (this is drupal_cron_run function) if you know exactly that cron won’t work more than 5 minutes:
if ($semaphore) {
if (time() – $semaphore > 3600) {
// Either cron has been running for more than an hour or the semaphore
// was not reset due to a database error.
watchdog(‘cron’, ‘Cron has been running for more than an hour and is most likely stuck.’, array(), WATCHDOG_ERROR);
// Release cron semaphore
variable_del(‘cron_semaphore’);
}
else {
// Cron is still running normally.
watchdog(‘cron’, ‘Attempting to re-run cron while it is already running.’, array(), WATCHDOG_WARNING);
}
}
Try to change change ‘3600’ to maximal time of working your cron-script (in seconds) in 2507 line. This error will disappear (but of cause other errors can occur;)
Thus if you set semaphore to 10 minutes and cron is launched every 6 minutes then if cron hangs it will be launched again.