Set Up Cron Jobs In Magento

Hi audiences, we are back with another article about interesting and useful technique in Magento that you will find it extremely necessary now and then to run some command automatically, ie. How to set up cron jobs in Magento. All Magento seniors agree that cron jobs do help them extensively in terms of time and resource savings. As a beginner, you are fortified to enhance your ability to set up and run your first cron job following our tips shared below. Note that cron only works if the server which your Magento hosts  is already setup for cronjobs.

Latest Update: We’ve just released the version 2.0 of Claue Multipurpose Magento 2 Theme, with with a bunch of performance improvements and exclusive features. Check this theme out now: Claue Magento Theme  2. 0 

claue2_edited (1)

Live Demo 

Claue – Clean, Minimal Magento 2&1 Theme is an excellent template for a modern and clean eCommerce store with 40+ homepage layouts and tons of options for shop, blog, portfolio, store locator layouts and other useful pages. Claue version 2. 0  comes with a bunch of  exclusive features including:

  • Being based on Luma theme.
  • Meet all standards of Magento Theme
  • Significant performance improvement
  • Compatible with most third-party extensions.
  • Fully compatible with Magento 2.4.x

This second advanced version completely differentiates from its previous one. Thus, if you are using Claue version 1 and want to update to Claue version 2, you can only rebuild a new website no rather than updating from the old version. Now, let’s get back the main topic.

There are two options to setup cron jobs for a Magento server:

1. Use cPanel to setup cronjobs

Log onto cPanel, move to Cron jobs:

img-1Select the parameters to set up a new Cron Job:

img-2You are able to either choose quick setup in the Common Settings or select individual options for Minute, Hour, Day, Month and Weekday.Note that:

Minute: how frequency in minutes per running time? Or at which minute of the hour it runs?

Hour: how frequency in hours per running time? Or at which hour?

Day: how frequency in days per running time? Or on which days of the month?

Month: how frequency in months per running time? Or in which months of the year ?

Weekday: On which days of the week?

Command: php -f /absolute_path_of_your_magento_root_folder/cron.php

Eg.php -f /home/abc/public_html/cron.php

After you have selected the options, click  “Add New Cron Job”

2. Use ssh to setup Cron jobs:

Log onto ssh account. To check if your server has Magento cronjob set up, run this command:

crontab –l

If not, you need to open crontab file to set it up:

crontab –e

Use “PgDn” on the keyboard to move to the final line and press  “Enter” to create a new line.

Input this line:

*/5 * * * * wget -O /dev/null -q > /dev/null

Note: */5 * * * *is the parameter to run the cronjob, in this case the cronjob is set up to run automatically every 5 minute every day, is your Magento website URL.

Press “Ctrl+X” and then press “Enter” to save the cronjob.

After you have established cronjob for the server, you are now ready to set up cronjob for Magento modules.  There are also 2 solutions to set up cronjob for modules, namely fixed and flexible time. For the fixed time choice it means you can set up a specific timeframe to run cronjob in your config.xml file, whereas the 2nd choice allows admin to adjust timeframe of the cronjob in backend panel.

  1. Fixed time:

You will set the time for cronjob in:


In between the tab:




Add the following code:





<cron_expr>*/5 * * * *</cron_expr>





</ modulename_cron_name>




modulename_cron_name: you give it a name

*/5 * * * *: is the parameter to run the cronjob, in this case the cronjob is set up to run automatically every 5 minute every day.

<model>modulename/observer::mothodName</model>: modulename is the name of the module, in folder Model, create a file named Observer.php as follows:


class Namespace_Modulename_Model_Observer


public function mothodName(){

your process…



  1. Create a function to set up flexible time for a cronjob in backend panel:

Firstly, you need to add the following code to your config.xml file like you did in the first solution:







</ modulename_cron_name>



And create Observer.php file like mentioned above, however, the difference of this 2nd solution lies in the fact that you don’t need to set up timeframe for the cronjob in config.xml file.

In order for admin to set time for a cronjob, you need to create a general configuration in system.xml file.

Go to: app/code/local/Name_Space/Module_Name/etc/system.xml

Add the following code to create a new tab for the module configuration board:

<crontab_setting translate=”label”>

<label>Crontab settings</label>







<frequency translate=”label”>














                <time translate=”label”>

                                <label>Start Time</label>









In folderModel, create a Cron.phpfile following this path:




class Namespace_Modulename_Model_System_Config_Source_Cron extends Mage_Core_Model_Config_Data


const CRON_STRING_PATH = ‘crontab/jobs/modulename_cron_name/schedule/cron_expr’;

const CRON_MODEL_PATH = ‘crontab/jobs/modulename_cron_name/run/model’;

protected function _afterSave()


$time = $this->getData(‘groups/ crontab_setting/fields/time/value’);

$frequncy = $this->getData(‘groups/ crontab_setting/fields/frequency/value’);

$frequencyDaily = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_DAILY;

$frequencyWeekly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY;

$frequencyMonthly = Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY;

$cronDayOfWeek = date(‘N’);

$cronExprArray = array(



($frequncy == $frequencyMonthly) ? ‘1’ : ‘*’,


($frequncy == $frequencyWeekly) ? ‘1’ : ‘*’,


$cronExprString = join(‘ ‘, $cronExprArray);

try {


->load(self::CRON_STRING_PATH, ‘path’)





->load(self::CRON_MODEL_PATH, ‘path’)

->setValue((string) Mage::getConfig()->getNode(self::CRON_MODEL_PATH))



} catch (Exception $e) {

throw new Exception(Mage::helper(‘cron’)->__(‘Unable to save the cron expression.’));




These are the two tips for Magento developers to set up cronjob for Magento server and modules. Whether you are a beginner or an expertise, we truly hope this article finds you well. All your comments and contributions to our blog are highly appreciated. Thanks for your time.

19931 Total Views 2 Views Today