If you have been using Magento eCommerce for some time, you have probably heard of Magento Cron, creating a Cron Job in Magento, and other such things.
What is Magento Cron?
In short, Cron is a “timer” used in Magento out of the box. It allows you to schedule and execute (periodic) Magento tasks automatically.
We are talking about such tasks as:
- sending out transactional emails
- updating currency rates
- cleaning up log files, etc.
In Magento, this module is called Mage_Cron and it is available to you if you have Magento eCommerce installed on your host.
Configuring Magento Cron
At any given time, there would be certain tasks (essentially, scripts) waiting to be executed or being executed via Cron in Magento.
Cron settings in Admin Panel determine how the queue of “Cron Jobs” is generated, and how the history of completed/failed tasks is handled.
To access the settings, go to System > Configuration. In the panel on the left, under Advanced, select System. Then, click to expand the Cron (Scheduled Tasks) section.
There, you get the following options (the values are in minutes):
Explanation (to the settings on the screenshot above):
- Cron Schedules will be generated every 15 minutes.
- Schedules will be generated 20 minutes prior to being executed.
- Any Cron Job that hasn’t been executed within 15 minutes will be marked as “missed”.
- The Cron history will be cleaned up every 10 minutes.
- Records of completed Cron jobs will be kept in the database for 60 minutes.
- Records of failed Cron jobs will be kept in the database for 600 minutes.
Before configuring Cron, make sure your Secure and Unsecure Base URLs are explicitly declared in Magento.
Note: Starting with Magneto Community 1.9.1, Cron Jobs are more important than ever before. In addition to indexing and other core functions, all Magento e-mails (including order confirmation and transactional) are now queued and sent according to your configured Cron schedule.
Important! You must configure Cron to run as the web server user. Otherwise, you will experience issues such as not being able to reindex from the Magento Admin.
Setting up a Magento Cron Job
If you have access to the control panel on your server (cPanel, Confixx, Plesk, etc.) setting up a Cron job is as easy as going to the Cronjob Manager inside your control panel.
Step 1: Make sure no other Cron Job has been set up calling the cron.php file in Magento root. If that is the case, remove it before adding this Cron Job.
Step 2: Add a Cron Job with the following parameters:
This means the Cron Job will be run every 5 minutes. It is very important that the cron.php file in Magento gets executed every five minutes. It is not recommended to change this to a longer interval.
Command: wget -qO- http://www.yoursite.com/cron.php
Remember to replace yoursite.com with the URL of the your Magento website.
Please note that you need wget for this. If you don’t have it installed yet, try the following for your distro: apt-get install wget (for debian/ubuntu-based distros) , yum install wget (for rhel-based), emerge wget (for gentoo).
Step 3: Please try to call the URL you have entered using your browser. A blank page should be returned. If the page can’t be found (404), this means the URL for the Cron Job manager of Magento (cron.php) is incorrect.
This way, the cron job won’t be executed and that it hasn’t been set up properly. It is really important you enter the correct URL – it is always the URL to the cron.php file sitting inside the root directory of your Magento installation.
Step 4: Finally, click ‘Add New Cron Job’.
Voila – you are all set! A new Cron Job has been created.
Typical Cron Issues
Although Cron appears to be a straightforward tool, there are certain typical problems admins face with it.
First, a previous admin may have set up tasks you are not aware of that should be executed via Cron.
Second, it’s essential to understand how creating a cron job works, so that you don’t create cron jobs that pile up and cause task delays.
Third, certain tasks you want Magento (or a Magento extension) to perform may require Cron to be set up correctly, and, again, you may not be aware of that.
Aitoc extensions that use Magento Cron
Server Load Monitor (Paid and Free)
Further Useful Reading
It dwells on the difference between cron.php vs. cron.sh among other things.
It talks about cron.php script in Magento and about testing your Cron.