Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How to debug Cron problems
 
benz001
Sr. Member
 
Avatar
Total Posts:  238
Joined:  2009-02-05
Sydney
 

Getting cron to work can be a pain so I thought I’d use this thread to note down some tips I’ve found in my struggles through it.

Log when cron runs

It can be hard to tell if cron really is running when you think it should be, you can check the database but that can be confusing. Fortunately it’s easy to add a magento log event to each cron call, just edit cron.php in your store root as follows then turn on logging in System > Configuration > Developer > Log Settings

Mage::app('admin')->setUseSessionInUrl(false);

try 
{
    Mage
::getConfig()->init()->loadEventObservers('crontab');
    
Mage::app()->addEventArea('crontab');
    
Mage::dispatchEvent('default');
    
Mage::log("Cron run"); //Add this line and you will get a log entry
catch (Exception $e{
    Mage
::printException($e);
}

Now whenever cron is triggered you will get an entry in /var/log/system.log like this:

2010-01-20T01:15:05+00:00 DEBUG (7): Cron run

Trigger Cron manually

To test the logging script or anything else cron related you can trigger it manually by pointing your browser to
http://yourstoreaddress/cron.php

Check the log file after hitting that address and you should see a new cron entry.

Understand the times that Magento and your server use

Magento internally sets all cron dates to occur in GMT, it actually overrides the server php time zone settings so that all log events and all cron time schedules are triggered in the GMT timezone - you can see this in Mage.php on line 527. All php time functions called within Magento will be in GMT as a result (like the timestamp in the log call above).

Magento then adds back your timezone offset based on your locale settings when it shows you times in the admin panel.
It does this so you can run multiple stores in different timezones based on your locale choice and ideally you would never know nor care about this - but it makes debugging cron events really confusing.

Worse, in 1.3.2.4 there are some bugs, if you enter in a trigger time for a product alert the time doesn’t get converted back to GMT from your timezone when its saved to the database, yet any reports on when product alerts were run is converted to your timezone on display. so its a nightmare to debug. In effect the alert will run as if you had entered it in GMT but will report as if it occurred in your timezone.

Check how cron is configured with your hosting company

Depending on your host’s setup crontab events may or may not execute as your normal account user, so some of the paths to trigger cron.php floating around the forum/net may not apply to your case (examples using wget or curl should be fine). If your log file shows that cron.php is not getting run, yet you can trigger it by hitting the cron page manually then contact your host and get them put together the appropriate cron entry for your system.

Anyone else got any tips to add?

 
Magento Community Magento Community
Magento Community
Magento Community
 
logarithm
Jr. Member
 
Total Posts:  9
Joined:  2010-04-27
 

THANKS FOR THE TIPS!

 
Magento Community Magento Community
Magento Community
Magento Community
 
PressMonkey
Jr. Member
 
Total Posts:  16
Joined:  2010-06-07
 

Awesome. Great info. Thanks a heap! grin

 
Magento Community Magento Community
Magento Community
Magento Community
 
tinotriste
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2008-09-09
Bolton, UK
 

Thanks a bunch!

 
Magento Community Magento Community
Magento Community
Magento Community
 
seansan
Member
 
Total Posts:  62
Joined:  2010-01-27
 

Super. Now what would you look at if this php script is run (verified)

But there is no message in the Magento log and CRON doesnt seem to be running

 
Magento Community Magento Community
Magento Community
Magento Community
 
chiefair
Mentor
 
Avatar
Total Posts:  1848
Joined:  2009-06-04
 

Magento’s cron submits job status to a table. Cron log monitor script to see that output.

Set up your Cron log so that you aren’t limited to a ridiculously short time span for monitoring finished jobs. Otherwise, all you see is that darn newsletter_send_all.

Go into your Advanced System Config and set Cron Success History Lifetime and Failure Lifetime both to 1440 so you are monitoring a 24 hour span of time.

You will now be able to see index operations, etc in the time stream. There will be about 300 jobs listed in your Jobs Successful section over the 24 hour timespan.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sashas7777
Sr. Member
 
Avatar
Total Posts:  90
Joined:  2012-04-25
New York, USA
 

Hi,

I can suggest you to look at the Magento errors Extension it have list of cron jobs and also it have list of enabled cron jobs.
Magento Error Logs Extension

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top