How to Config Cron Jobs in Magento

Cron Jobs support is a key feature offered by Magento. From sending order confirmation emails to validating special price. Multiple core functionalities of Magento are built on the top of Cron Jobs. So configure Cron Jobs correctly is crucial to the success of your online store.

How to Config Cron Jobs in Magento

By default, Magento comes with Cron Jobs features. There are also 3rd party extensions like Aoe_Scheduler, which offers more advanced Cron Jobs management and optimization. We are not talking about those extensions here. Instead, this post will go through the setup process of the default Cron Jobs function offered by Magento itself.

Configure Magento Cron Jobs from Command Line

If you are familiar with Linux environment and Linux Cron Jobs, it may be pretty straightforward to add the Cron Jobs Magento required from Command Line.

Just log into your server, and then switch to the Magento file system user, using SU command, and then using Crontab -e command to open the Cron Jobs editor.

After entering the command above, pressing ESC quits from insert mode to normal mode, and then enter :wq to save, quite easy, right?

Configure Magento Cron Jobs using CPanel

If you are not very familiar with Linux commands, no worries! Most of the hosting solutions have CPanel ready for you. Just log in your Cpanel account, search for Cron, and then go to Cron Jobs

Cpanel-cron

It also offers some useful presets of Cron Jobs options, such as execute your Cron Jobs once per minute, or once per 5 minutes, etc …

Cpanel Cron Job Configuration

Last, in the Command box, enter  sh /path_to_Magento_root/cron.sh

Then we are done!

How often should you run Cron Jobs for Magento?

Whether you use command line or CPanel to set up Magento Cron Jobs, you will need to set the frequency of Cron Jobs execution. You may find different answers to how often you should run Cron Jobs after searching on the Internet. My development team and I personally would like to use 3 mins or 5 mins as an interval to run the Cron Jobs for Magento.

Execute Cron Jobs every 3 mins:

Execute Cron Jobs every 5 mins:

But I have seen people using 1 min, 10 min.

Magento Cron Jobs Settings in Back-end

Last, let’s take a look at some Cron Jobs Settings in Magento Backend.

Go to System -> Configuration

From the left Menu, Find Advanced -> System -> Cron (Scheduled Tasks)

You will see couple options we have here:

Magento Cron Job Configuration

Schedule ahead for: Cron Jobs tasks will be generated for this amount of time ahead.
In the example, if a Cron Jobs task is scheduled at 15:15, it will not be generated and then added to Cron_schedule before 15:00

Missed if not run within: if Cron Jobs is executed within setup minutes after the task was scheduled, it will be executed. Otherwise, it will be marked as ‘missed ’in Cron_schedule table.

History cleanup every: Magento will clean up history not more than setup amount of minutes.

Success history lifetime: successfully executed tasks will be stored in Cron_schedule table for this amount of minutes.

Failure history lifetime: Tasks that have status ‘error’ and ‘missed’ will be stored in Cron_schedule table for this amount of minutes.