If you wish to run a piece of code periodically, for example every hour, or at midnight every day, the best way to do this is to put it in a CRON task.

Magento manages its own CRON tasks using the internal “crontab” functionality. This queues up all the Magento code that wishes to be automatically run without user intervention.

This feature allows you to safely and easily create your own extension and lets you add your own tasks to Magento’s CRON functionality.

Let’s begin…

All it needs is 3 simple files.

You will need to create the folder structures to accommodate the files.


Note: the line

This sets the frequency at which your cron task will execute, and is currently set to every 30 minutes. For more information on CRON expressions see here.


/app/code/local/Mycompany/ Myextension/Model/Myextension.php

And that’s it!

Simply put your PHP code into the cron() method and it should run as frequently as you’ve specify in config.xml

If for some reason your code doesn’t run, check your system and/or exception log files for possible code errors, and check that your hosting solution has a CRON setup to run Magento’s cron.php

Additionally, check that the correct case is used in file and folder names and in the xml and php files for the extension and module names.

NuBlue provide professional, high quality UK Web Hosting on Shared, VPS and Dedicated platforms.

Subscribe to RSSShare on Google+Share on LinkedInShare on StumbleUponShare on TumblrShare on FacebookTweet about this on Twitter