I have written a custom import script that reads data from CSV and creates/updates products in my store. The script is scheduled to be executed once per day (in the night) with the cron. This is the cron configuration in the custom module that executes the import

                    <cron_expr>0 1 * * *</cron_expr>

The process takes a long time to execute (there are about 4000 products to process) and on the production server the max_execution_time is set to 30 (5 minutes) and I can not change it (set_time_limit does not work).

So I need to do the import in another way. I thought that the best way would be to have a 'trigger' script to be executed with cron. Then trigger script would start the import and before the time limit is reached re-run the import process.

I was wondering how this could be achieved in Magento or if there is a better way to do that.

1 Answer 1


A long term cron web execution should be disencouraged and splitting the import may result in a very mess code ;)

My suggestion is to workaround it with two possible options:

Option 1 - cron by shell:

You can both call your cron via shell (best if using AOE_Scheduler module).

Option 2 - script by shell:

You can create a Magento shell script to add to your cron:


class My_Import extends Mage_Shell_Abstract {
    public function run() {

$script = new My_Import();

When running from shell you do not have the same time limits as the web has.

This script must be created inside /shell folder.

You can run it with:

php -q scriptname.php

And of cource you can add to your crontab for a scheduled importer.

  • I managed to do it with the option 2. I did not know that Magento can override that settings with shell scripts. Thanks a lot!
    – giani.sim
    Feb 25, 2016 at 14:20
  • 1
    It is not Magento itself, it is because it uses php-cli instead of standard PHP. PHP from cli is usually configured with no time restrictions. Feb 25, 2016 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.