Site icon GetPageSpeed

Magento 1.x cron jobs setup

Magento cron jobs

Magento cron jobs

Make sure to setup Magento cron jobs properly:

*/2 * * * * /bin/sh /var/www/html/cron.sh cron.php -m=default
*/2 * * * * /bin/sh /var/www/html/cron.sh cron.php -m=always

Add the lines above to the crontab of the user that is running your Magento site.
It is important to run Magento cron jobs via cron.sh script.

This is the most correct and performance efficient way to make sure Magento cron jobs are running:

Beyond Magento Crons

Larger stores would want to export their products regularly to feed-like files (XML, CSV, and similar formats),
all to promote their products through third-party services.

Because Magento’s internal cron system isn’t perfect, the long-running export tasks may and will hold off the execution of other standard tasks.
This is not desired.

It is recommended to use Aoe_Scheduler plugin and its scheduler_cron.sh launcher in favor of the standard cron.sh.

This will not only allow you to enrich your Magento cron system with the ability to track tasks PID, memory usage, etc.
But also you can designate specific tasks to be run in parallel, by using the cron groups feature.

Running Magento cron tasks outside Magento system

For the mentioned long-running job, if you’re not willing to use Aoe_Scheduler’s groups, you can simply set up specific crons to be run as a regular, separate Linux cron task.

For this, you will create a shell/... script which will launch it and disable execution under the Magento cron system.

Citing reference on how to do this:

Remove from the module’s config.xml the cron task in question. Keep a note of the <model>module/observer::methodName</model> line.

Then create a file resembling an example within Magento’s shell/ folder. Something like:

<?php
require_once('/path/to/magento/app/Mage.php');
Mage::app('admin');
require_once '/path/to/magento/shell/abstract.php';
class Mage_Shell_YourTask extends Mage_Shell_Abstract
{
    /**
    * Run script
    *
    */
    public function run()
    {
        // Call the method here that was previously configured in the module's cron configuration
        $model = Mage::getSingleton('module/observer');
        $model->methodToCall();
    }
}
$shell = new Mage_Shell_YourTask();
$shell->run();

Now you can simply set up that tasks with desired scheduled in the Linux crontab like so:

30 3 * * * php /path/to/magento/shell/foo.php

This will run these Magento tasks using the Linux cron system, at 3:30 AM every day.

Exit mobile version