Cron.php Running Twice – Magento Cron.sh Issue

cron

I have a cron job set up to run the cron.sh file every 5 minutes, as per the installation guide. I have checked the server's cron log history and it is correctly running the job on schedule.

I added file_put_contents('cronlog.txt', date('c') . "\n", FILE_APPEND); to the end of the try block in cron.php to verify, but it's logging two identical dates every 5 minutes, like cron.php is calling itself recursively.

Is this normal behaviour? If not, any ideas as to what could cause such strangeness?

Best Answer

On newer versions this is expected. If you take a look at cron.php this part would get executed:

        shell_exec("/bin/sh $baseDir/cron.sh $fileName -mdefault 1 > /dev/null 2>&1 &");
        shell_exec("/bin/sh $baseDir/cron.sh $fileName -malways 1 > /dev/null 2>&1 &");

which then loops through cron.sh to call the cron.php again two times. It gets executed once in always mode and another time as default

    Mage::dispatchEvent($cronMode);

Further reading http://davidalger.com/development/magento/a-new-breed-of-cron-in-magento-ee-1-13-2/

Related Topic