Don't Interrupt cron.php When Debugging

If you want to see what's going on when Drupal's cron.php script runs, one thing you can do is to set a breakpoint in a module's implementation of the hook_cron() function, and call cron.php directly from your debugger. There you can step through your breakpoints, examine variables, and hopefully zero in on your problem.

The particular problem I was having involved nodes losing some of their taxonomy information when getting published by the scheduler module as handled by the scheduler_cron() function. (Taxonomy access control was to blame; it was disallowing anonymous list access to the affected taxonomy terms, and since cron.php typically runs as an anonymous Drupal user those terms were getting ignored.) Because I didn't want to have to keep adding new test nodes, I stopped execution of the cron script as soon as I saw the problem happening.

The only problem is that this interferes with the normal behavior of cron.php, which sets a system variable called cron_semphore while running, which it then deletes it when finished. It does this to prevent more than one instance of cron.php from running concurrently; if you call cron.php and it finds the cron_semaphore variable, you'll see a watchdog entry that reads "Attempting to re-run cron whilte it is already running," and cron.php stops dead.

If you've meddled with the normal flow of cron.php and it stops before removing the cron_semaphore variable, you'll probably have to remove it yourself. You can do this by installing the devel module and using it 'Variable editor' tool. After you delete cron_semaphore, you should also use the devel module's 'Empty cache' tool to remove all traces of it from the cache. Having done this, you should be able to run cron.php again normally.

Just query against the data

Just query against the data base. Its just DELETE FROM variable WHERE name = 'cron_semaphore'

of course use your table prefixes if you are using them

Proceed with caution

You're right, direct querying the database is the fastest way to go, but I always get a little bit squeamish about recommending it to others because the potential for disaster is so much higher, hence the Devel module variable editor approach.

Note to the adventurous: If you do decide to query the DB directly, always take a backup snapshot before doing ANYTHING. mysqldump and/or drush SQL tools are your friends!

it will recover

If Drupal sees that cron has been running for more than an hour (i.e. your interupted cron job) it will assume that something got hung up and the next time cron.php is called it will let it do its thing.

Interesting, thanks for the

Interesting, thanks for the clarification. I had seen the "Cron has been running for more than an hour and is most likely stuck" error, but I didn't wait long enough before fixing the problem manually to see Drupal recover automatically.

heh

http://en.wikipedia.org/wiki/Observer_effect_(physics)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><p><div> <br><img>
  • Lines and paragraphs break automatically.

More information about formatting options

Verification
This question is for testing whether you are a human visitor and to prevent automated spam submissions.