Drupal: Quick Cron Diagnostic
In this article I would tell you how to find our the reasons of why cron hangs up and fix them. Read the solution options below.
Indexing
Reduce the number of documents for indexing at a single cron start on search settings page. It’s better to run cron once a day.
Email distribution
If you have installed simple news, it may be a reason of cron hanging up. Sending a lot of emails doesn’t have a positive effect on cron.
Not enough time
try to change cron.php file in the following way:
// If not in ‘safe mode’, increase the maximum execution time:
// if (!ini_get(‘safe_mode’)) {
set_time_limit(1800);
// }
I.e. comment these lines.
Who is in fault?
Please do the following to figure out which module is in fault that cron hangs up: in includes/module.inc, in the last function (function module_invoke_all()), replace 404-405 line:
foreach (module_implements($hook) as $module) {
$function = $module .’_’. $hook;
with this one:
foreach (module_implements($hook) as $module) {
if ($hook == ‘cron’) {
watchdog(‘cron_runs’, $module); }
$function = $module .’_’. $hook;
Thus you will have a new category “cron_runs” in a log. The category will contain a list of modules which called cron. The last module is a “guilty” one.
Please do not forget to get all files back after you make diagnostics.
Message: “Trying to restart…” when a procedure is performing.
The reason of why you see this message is that wget can call cron.php up to 20 times at a stretch if it doesn’t get the acceptable response. Read more info here: http://drupal.org/node/150972
You can also close access to a cron “from outside” in this way:
Add the following code to .htaccess file:
<Files “cron.php”>
Order deny,allow
Allow from xxx.xxx.xxx.xxx
Deny from all
</Files>
Replace xxx.xxx.xxx.xxx with IP you want to enable cron launch from.
Good luck!