cancel
Showing results for 
Search instead for 
Did you mean: 

cron.php - cron.sh infinite loop

cron.php - cron.sh infinite loop

Hello,

 

I'm having a strange problem since Januarty when our server was updated to PHP 5.4. I thought it's just a incompatiblity with Magento 1.9.0, so I'm udating it right now to 1.9.1.1, but it's the same, even with PHP 5.5.

 

So, the problem is:

I had to shut down cron jobs a while ago, because it caused an infinite loop between cron.php and cron.sh. They are just throwing the process back and forth between each other, causing a constant  100% CPU utilization. And in the meantime no cron tasks were made.

 

It was working fine for half a year before January, so the setup should had been ok in the admin panel. I turned off cron in cPanel, and trying to start it from the prowser instead, bt it's the same. The only was to stop is renaming one of the cron files.

 

The worst thing is that in 1.9.1.1 I should no more disable cron jobs due to the email queue.

 

Thanks for any idea.

9 REPLIES 9

Re: cron.php - cron.sh infinite loop

Does this still happen, even after upgrading to 1.9.2.1?

Magento Moderator since 2009
Keep Calm and Clear Cache!

Re: cron.php - cron.sh infinite loop

Yes, it appears in 1.9.2.1 too. But this might be hosting issue (despite the fact that hundreds of other Magento sites runing at them - probably on different servers), because previously it stopped working from one day to another, without any change in code.

 

Anyway, I've "fixed" it by adding $isShellDisabled = true; to cron.php, so it's just working fine.

Re: cron.php - cron.sh infinite loop

Hi is there a fix for this? We are experiencing exactly the same issue here.

 

PHP 5.5 and Magento 1.9.2.1

 

Our hosting company has investigated and says the cron.sh/cron.php is getting into a loop and causing the server to reach 100% CPU.

Re: cron.php - cron.sh infinite loop

As a temporary fix I would recommend you to add the following line to cron.php before the try { (line 50):

 

 

$isShellDisabled = true;

 

And set the cron job to run cron.php instead of cron.sh.

 

Unfortunately I haven't found any other solution yet, nor the source of the problem. Actually now I'm working on the upgrade to Magento 2, hopefully there will be no problem (also moving to a VPS so there will be more room to investigate if it appears).

Re: cron.php - cron.sh infinite loop

Thanks, I have added that to the cron.php

 

Its strange because it runs fine all week and then suddenly it just happens. I could understand if it does it every 5/10/20 mins (whatever the cron is set to)..

 

Weird..

 

Lets see if this solves the issue. I just downloaded the cron.php from Magento site for 1.9.2.4 and it differs slightly, so im half tempted to try and use that.

Re: cron.php - cron.sh infinite loop

In my case it was running perfectly for half a year, and after that suddenly it stopped working completely, looping all  the time. Maybe there were some changes in the server configuration or something, I have no idea as we are on a shared hosting right now.

Re: cron.php - cron.sh infinite loop

So what does $isShellDisabled = true doing? (never really had to touch the cron.php or cron.sh files)

 

Telling it to run the job through Magento's core code instead of using the shell script?

 

Cheers for the heads up we will keep an eye on it.

Re: cron.php - cron.sh infinite loop

Sorry, I did not check the actual code, just wrote my previous reply according to my memories. Now I had time to check it deeper. You have to add $isShellDisabled = true; before the try { around line 50, otherwise it will be overwritten.

 

What it does is that it disable the sh call between line 62-69:

        } else if (!$isShellDisabled) {
            $fileName = escapeshellarg(basename(__FILE__));
            $cronPath = escapeshellarg(dirname(__FILE__) . '/cron.sh');

            shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -mdefault 1 > /dev/null 2>&1 &"));
            shell_exec(escapeshellcmd("/bin/sh $cronPath $fileName -malways 1 > /dev/null 2>&1 &"));
            exit;
        }

The problem with our cron.sh call was that sh was that it was available and working indeed, but it called back the cron.php again, and here you go, an infinite loop.

 

Actually as I have checked the code once again, it looks like this part can be reached when there is no -m command line parameter when calling the cron.php. Honestly, I have never seen any tutorial mentioning that it is necessary,  but after reading this reply, it makes some sense:

http://magento.stackexchange.com/questions/63707/which-cron-script-is-best-to-run-cron-php-or-cron-s...

 

So according to this solution you should use a similar cron job:

*/5 *   * * *   www-data /bin/sh /path/to/magento/cron.sh cron.php -m=default
*/5 *   * * *   www-data /bin/sh /path/to/magento/cron.sh cron.php -m=always

(www-data is your username and you may not have to use it, also sh location might differ)

 

Anyway, a fallback mode would be great for this case, when the admin don't set up the -m parameter.

 

Re: cron.php - cron.sh infinite loop

 Did this work for you? We seem to be having a similar issue where it occurs at random times and not according to the cron interval.