1

Some years ago i wanted to turn off watchdog because it's memory and db consumption, but today i need info about why my cron isn't running because need to use Search module from now?

Trying to run cron manually (admin/reports/status/run-cron) return

Cron run failed.

calling /cron.php and running from server's command line has no return,

How can i debug this?

or

There is any other way to turn on logging?

admin/settings/logging/dblog

has no return

SELECT * FROM `watchdog`

MySQL returned an empty result set

function watchdog()

still there in bootstrap.inc

settings.php and .htaccess free from any relevant "error", "watch", "dog", "bdlog", "repor" keywords (have no php.ini)

/modules/dblog/dblog.module

still untouched. XML sitemap and Search is disabled

No logging, no cron, i am puzzled. Thanks for any help.

2

To enable the recording of the watchdog() messages, you just need to enable the Database logging module (short name: dblog). Once you enable it, on admin/reports/dblog you will start reading the recent log entries.

As for the possible error that could return cron, they are the following ones:

  • Cron has been running for more than an hour and is most likely stuck
  • Cron is already running and you try to re-run it

This is evident from Drupal code. The function that is executed when you go to admin/reports/status/run-cron is system_cron_run(), which returns the error you are seeing when drupal_cron_run() doesn't return TRUE. This is that function code.

  // Try to allocate enough time to run all the hook_cron implementations.
  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', '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);
    }
  }
  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');

    // Record cron time
    variable_set('cron_last', time());
    watchdog('cron', 'Cron run completed.', array(), WATCHDOG_NOTICE);

    // Release cron semaphore
    variable_del('cron_semaphore');

    // Return TRUE so other functions can check if it did run successfully
    return TRUE;
  }

As for why Drupal thinks cron is still running, that happens when an error in the code (generally one of the hook_cron() implementations) doesn't permit drupal_cron_run() to execute the following line:

    // Release cron semaphore
    variable_del('cron_semaphore');

This means that to debug why cron doesn't work properly, you need to check any hook_cron() implementation, and see what is wrong with them. The problem could also be an implementation of hook_node_view() which is wrongly calling drupal_goto().

  • Thank you, enabling the Database logging was the first solution. But the dump result of drupal_goto() return only the defaults except the $path: "string(20) "admin/reports/status" NULL NULL int(302)". And PHP filter is disabled and there is no any hook in template.php, and in any other template file. And yes, you are right "Attempting to re-run cron while it is already running." – eapo Mar 30 '16 at 22:26
1

If you have Drush available on the site, you can run this from the document root for that Drupal site:

drush cron

It should output errors so you can further troubleshoot. Also, if you have drush, you can enable dblog like so:

drush en -y dblog
1

Enabling the Database logging was the solution to enable watchdog (thank you @kiamlaluno), then this is the message after running cron:

Message Attempting to re-run cron while it is already running.

Manually deleting cron_semaphore cause

Cron ran successfully

but with Search module enabled cause

Internal Server Error - 500

Then just changing this in search.module resolved the problem:

 function search_cron() {
  // Update word index
--  foreach (module_list() as $module) {
++  foreach (module_list(true, true, false) as $module) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.