druapl Cron run failed
一个新闻资讯类的新站采用drupal驱动,使用了其上的openpublish集成安装包,在增加了xmlsitemap后提示Cron run failed. 在drupal内置的recent log entries中显示
Attempting to re-run cron while it is already running.
以及在每隔一个小时显示:
Cron has been running for more than an hour and is most likely stuck.
无解,求助google,终于找到:
cron函数的定义在includes/common.inc中function drupal_cron_run(){} 简单的解决方式是在运行corn前删除semaphore值,使cron解锁。如下:
function drupal_cron_run() {
// If not in 'safe mode', increase the maximum execution time:
variable_del('cron_semaphore');
并且一些log记录:完整修改drupal_cron_run()代码如下(修改处用粗体表示):
function drupal_cron_run() {
// If not in ‘safe mode’, increase the maximum execution time:
variable_del(‘cron_semaphore’);
if (function_exists(‘set_time_limit’)) {
@set_time_limit(240);
}// Fetch the cron semaphore
$semaphore = variable_get(‘cron_semaphore’, FALSE);
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’, t(‘Cron has been running for more than an hour and is most likely stuck.’), WATCHDOG_ERROR);
// Release cron semaphore
variable_del(‘cron_semaphore’);
}
else {
// Cron is still running normally.
watchdog(‘cron’, t(‘Attempting to re-run cron while it is already running.’), WATCHDOG_WARNING);
}
}
else {
// Register shutdown callback
register_shutdown_function(‘drupal_cron_cleanup’);
// Lock cron semaphore
variable_set(‘cron_semaphore’, time());
// Iterate through the modules calling their cron handlers (if any):
// module_invoke_all(‘cron’);
$log_timing = variable_get(‘cron_log_times’, ’1′);
foreach (module_implements(‘cron’) as $module) {
watchdog(‘cron’, t(‘Cron processing initiated for module: @module.’, array(‘@module’ => $module)));
if ($module == “search”) continue;
$function = $module .’_cron’;
if ($log_timing) {
timer_start($function);
if ($log_timing == ‘debug’) {
watchdog(‘cron’, t(‘Cron processing initiated for module: @module.’, array(‘@module’ => $module)));
}
}
$function();
if ($log_timing) {
$timer = timer_stop($function);
watchdog(‘cron’, t(‘Cron time elapsed for @module is @millisecs ms.’, array(‘@module’ => $module, ‘@millisecs’ => $timer['time'])));
}
}
// Record cron time
variable_set(‘cron_last’, time());
watchdog(‘cron’, t(‘Cron run completed.’), WATCHDOG_NOTICE);
// Release cron semaphore
variable_del(‘cron_semaphore’);
// Return TRUE so other functions can check if it did run successfully
return TRUE;
}
}
/**
* Executes a cron run when called
* @return
* Returns TRUE if ran successfully
*/
function drupal_cron_run() {
// If not in 'safe mode', increase the maximum execution time:
variable_del('cron_semaphore');
if (!ini_get('safe_mode')) {
set_time_limit(240);
} // Fetch the cron semaphore
$semaphore = variable_get('cron_semaphore', FALSE);
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', t('Cron has been running for more than an hour and is most likely stuck.'), WATCHDOG_ERROR);
// Release cron semaphore
variable_del('cron_semaphore');
}
else {
// Cron is still running normally.
watchdog('cron', t('Attempting to re-run cron while it is already running.'), WATCHDOG_WARNING);
}
}
else {
// Register shutdown callback
register_shutdown_function('drupal_cron_cleanup');
// Lock cron semaphore
variable_set('cron_semaphore', time());
// Iterate through the modules calling their cron handlers (if any):
// module_invoke_all('cron');
$log_timing = variable_get('cron_log_times', '1');
foreach (module_implements('cron') as $module) {
watchdog('cron', t('Cron processing initiated for module: @module.', array('@module' => $module)));
if ($module == "search") continue;
$function = $module .'_cron';
if ($log_timing) {
timer_start($function);
if ($log_timing == 'debug') {
watchdog('cron', t('Cron processing initiated for module: @module.', array('@module' => $module)));
}
}
$function();
if ($log_timing) {
$timer = timer_stop($function);
watchdog('cron', t('Cron time elapsed for @module is @millisecs ms.', array('@module' => $module, '@millisecs' => $timer['time'])));
}
}
// Record cron time
variable_set('cron_last', time());
watchdog('cron', t('Cron run completed.'), WATCHDOG_NOTICE);
// Release cron semaphore
variable_del('cron_semaphore');
// Return TRUE so other functions can check if it did run successfully
return TRUE;
}
}
原文来自:http://www.ebizontek.com/drupal-cron-stuck-log-progress