Cron System In Magento


Magento Cron System is used to run tasks on recurring basis as with any cron based system. “cron.php” located in magento base folder is the main entry for magento cron system.Magento cron you need to put “” in your web server cron job

There are various default cron job setup already in magento, so its recommend that you setup cron in magento. The default cron jobs in magento are related to log cleaning, newsletter, product stock notifications, currency updates.


Add cron to your module

Add following xml to your custom module’s config.xml

                  <cron_expr>0 2 * * *</cron_expr>
Magento also uses a table “cron_schedule” where is stores the status of all cron jobs. This is also a useful table which you can use debug your cron jobs.
There are various settings options for cron in admin which you can configure located at “Sytem -> Configuration -> Advanced -> System -> Cron”.

These settings are given below :

  1. Generate Schedules Every: After how many minutes should we generate a new cron entry in database
  2. Schedule Ahead for: How many minutes ahead should the cron entry be done in database.
  3. Missed if Not Run Within: Mark status as missed if cron has not run with these many minutes
  4. History Cleanup Every: Delete cron entry after how many minutes
  5. Success History Lifetime: After how many minutes to delete a cron entry with status success
  6. Failure History Lifetime: After how many minutes to delete a cron entry with status failure

Cron job details in Magento

To implement cron in magento, follwing files refers,

1. “cron.php”
2. “Mage_Cron_Model_Observer”
3. “app/code/core/Mage/Cron/etc/config.xml”
You can find “dispatch()” function under “Mage_Cron_Model_Observer” class.