Magento – Cron Constantly Running

cronPHPschedule

I am having issues with cron.php constantly running. I never had an issue with this until I upgraded to Magento CE 1.9.1.1. My hosting provider actually had to disable cron.php because it was causing a high load on the CPU. I installed AOE Scheduler and disabled some tasks which weren't necessary. I then had my hosting provider re-enable access to cron.php. However, cron will not run on the server even though I have a cron job setup correctly. I then decided to manually run the cron job by entering it's address in my internet browser's address bar. Once again, cron.php would constantly run and not stop, causing a high load on the CPU. The only way I could get it to stop was to rename cron.php to something like cron.BAK.

Cron tasks do run when I use AOE Scheduler to run the task immediately. However, I can create a schedule with AOE Scheduler and cron isn't running those tasks because it still isn't being executed by the server.

My question is two fold…

  1. How do I find out why cron.php won't stop running? Is this an issue with 1.9.1.1? I never had this issue until I upgraded from 1.9.1.0 to 1.9.1.1.

  2. Why isn't the server executing the cron job I have setup? Once again, I never had this issue until I upgraded to 1.9.1.1.

Right now, I'm mainly concerned with question #1. Question #2 is a low priority until I can get cron.php to run the tasks it's supposed to run and then stop. It's becoming a real pain because I'm getting hounded by my hosting provider about the high CPU load.

Best Answer

You should not call/run cron.php directly but cron.sh via system cronjob/crontab instead.

I can recommend Fabrizios Blogpost for more information about the Magento cron:

cron.php vs. cron.sh

In Magento’s root folder there’s a cron.php file and a cron.sh file. Briefly explained cron.sh internally calls cron.php and takes care of not executing more than one process in parallel. That’s a good thing, right? Well, sometimes… If you have long running tasks (e.g. a product import implemented as a task), these tasks will prevent anything else from being executed until the task has finished. You might have some other important tasks that shouldn’t wait or be skipped just because another task is running. Check the “Missed if Not Run Within” setting to configure the maximum delay a task can have to still be executed.

On the other hand using cron.php will start a new process every time it’s being called which could easily result in performance problems or race conditions for tasks operating on the same data. This is why cron.php should not be called directly. Find out more about cron groups later in this blog post for a nice solution on how to handle this situation.

http://www.webguys.de/magento/tuerchen-08-magento-cron-demystified/