12

I spent almost 3 days and cant able to understand and make the Magento Cron to process the scheduled tasks. I am running Magento 1.9.1.0 and recently noticed that order emails are now queued instead of sending instantly. I understand the necessacity but cant able to make the system to pick the queues.

Here is my seeing for Cronjob. enter image description here

Here is my cronjob command line. enter image description here

Here is how the tasks are created in cron_schedule table. enter image description here

Since the records are created in cron_schedule table i think the Cron is running once in every 5 minutes. If I manually delete these records via PhpMyAdmin the records are created automatically after some time.

But the status of the tasks remains 'pending' and never complete. Not sure if something wrong in my configuration or I am missing anything. Can someone please help me how to make the scheduled task run on time. Also why multiple records are created for one job code?

Update

I cleared the entire table and the cron created the scheduled jobs. All the jobs are in pending state and never run even waiting more than 60 minutes. Something is wrong in Magento 1.9.1

Update 11/02: Today I did some more analysis on the process.

I edited the cron.php as below

echo 'iam before mdefault 1';
shell_exec("/bin/sh $baseDir/cron.sh $fileName -mdefault 1 > /dev/null 2>&1 &");
echo 'iam before malways 1';
shell_exec("/bin/sh $baseDir/cron.sh $fileName -malways 1 > /dev/null 2>&1 &");
echo 'i returned success';

I edited the Mage_Cron_Model_Observer class as below

public function dispatch($observer) {
  echo 'iam inside dispath';

My understanding was when the cron runs the -mdefault it should call the dispatch function and the execute will happen. But what happened was as below in the cron output.

Content-type: text/html

iam before mdefault 1iam before malways 1i returned success

It means the dispatch doesn't called atall...

One another try

I manually changed the variable $isShellDisabled = true; and I changed the below in cron.php.

if ($isShellDisabled) {
  echo 'before always';
  Mage::dispatchEvent('always');
  echo 'after always';
  Mage::dispatchEvent('default');
  echo 'after default';
} else {
  Mage::dispatchEvent($cronMode);
}

The cron output for the above is as below

Content-type: text/html

before alwaysiam inside dispath alwaysafter always

Now it calls the 'dispatchAlways' but not the 'dispatch'

None of the answers helps me. It never picks the scheduled tasks. I.e when the Cron runs for the first time it successfully created the tasks in the table. But it never executes the task.

  • What happens when you run cron.php from a web browser? It will be a blank page, but I mean what happens to your cron tasks? – seanbreeden Feb 9 '15 at 15:28
  • Try using the bash script: */5 * * * * /bin/sh PATH_TO_PRODUCTION/cron.sh if available. – Phil Birnie Feb 9 '15 at 15:57
  • @seanbreeden, when I run via URL on browser it shows a blank page. Nothing has happened to the tasks.. I updated the question with the new set of tasks created... – Malaiselvan Feb 9 '15 at 15:58
  • @PhilB, .sh doesn't make any difference. It is similar the pending tasks are pending for ever but I am sure the cron is running for every 5 minutes. – Malaiselvan Feb 9 '15 at 17:24
  • did you try to empty the cron_schedule table? Check if it get's filled up with new tasks after an hour or so – Sander Mangel Feb 10 '15 at 21:58
3

It was the PHP version of Cron Jobs.

The PHP version was set correctly for the site which is why it was working; however Cron Jobs was running at server native PHP 5.3 which is why I was getting the errors only when running Cron. I updated to version 5.5.

Changed Cron command:

php /home/mydomainname/public_html/cron.php
to
php55 /home/mydomainname/public_html/cron.php

or in hostgator:

/opt/php55/bin/php /home/mydomainname/public_html/cron.php

in cron.php

$isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;

After this line, add:

$isShellDisabled = true;
  • The mention of running cron.php in a specific PHP version (ea-php70 in my case) fixed the issues I was running into: run php -v in terminal to see which PHP version the terminal is using. In my case it was 5.6. So I had to force the usage of PHP 7.0 by changing php to ea-php70 in crontab -e. Thanks! – Daan van den Bergh Nov 29 '17 at 12:49
2

did you try to empty the cron_schedule table? Check if it get's filled up with new tasks after an hour or so.

Also you can use Aoe_Scheduler to disable specific cronjobs. See if any particular one might cause an error that halts all the other tasks.

The way Magento cronjobs are set up a fatal error in a script will cause the execution of all of the tasks to fail

  • Thanks for the answer. Does the fatal error captured in any log? I updated few more findings on my case and updated the same in my question. – Malaiselvan Feb 10 '15 at 22:28
  • @seanbreeden : Today I noticed that when I launch the Cron.php via web browser it works great by picking the schedules. This proves there is no fatal error in any of the script. Any idea why the cron is not running via crontab? – Malaiselvan Feb 11 '15 at 21:51
2

As a first step I would suggest reverting your settings back to Magento's default cron settings:

Magento Cron Defaults

There is an issue with your current settings: your schedule is generated every 15 minutes but only scheduled ahead for 5 minutes which leaves a 10 minute gap.

  • Thanks. Even after I reset to default it doesn't work. When the first time it runs it created all the jobs in cron_schedule table with the scheduled time. The jobs are never picked and stays in the table as pending for ever. One thing I noticed after setting $isShellDisabled = true; and when I launch the Cron.php via browser the jobs are picked but not via CronTab. – Malaiselvan Feb 14 '15 at 0:39
  • This problem has not yet solved. Will there be a problem with my hosting provider. I see the script triggered at regular intervals but only the jobs are not picked. Also will it be a problem since I migrated from 1.8? – Malaiselvan Mar 20 '15 at 3:20
  • Does your cronjob have enough memory? Try the error logs to see if there is anything in there that could help. – Kristof at Fooman Mar 22 '15 at 21:46
  • this problem is not yet solved... Everyday I am breaking my head. Error logs? where can I see those? – Malaiselvan May 7 '15 at 20:50
  • @Malaiselvan for error logs please check with your system admin or webhost as they should know the location and how to access the server's error log. Also it might help to manually run the cron job from the command line - try both php -f cron.php and ./cron.sh to see if they produce anything to investigate further. – Kristof at Fooman May 11 '15 at 3:39
1

Same problem for me.

"Too late..." error found.

After cleaning cron_schedule table, cron.sh stopped working (not scheduling anymore).

Worked only after killing all old Cron processes.

  • In my case when the Cron runs for the first time it successfully created the tasks in the table. But it never executes the task. :-( – Malaiselvan May 7 '15 at 21:10
1

I had the same problem. My issue was timezone-specific: the created_at and scheduled_at columns in the cron_schedule table should be UTC+0, my entries were UTC+2.

To verify this you can simply set the dates from created_at and scheduled_atto yesterday and wait until the next cron schedule.

Hope that helps someone!

1

On Bluehost, in cron.sh change

 PHP_BIN=`which php`

to

 PHP_BIN="php54s"

By default in the shared hosting it runs PHP 5.2.

I also had to change cron.php, replacing the two $isShellDisabled lines with $isShellDisabled = true;

To get rid of PHP warnings, I also added these lines before

$_SERVER['SCRIPT_NAME'] = 

if (empty($_SERVER['SCRIPT_FILENAME'])) $_SERVER['SCRIPT_FILENAME'] = '~/public_html/cron.php';
if (empty($_SERVER['SCRIPT_NAME'])) $_SERVER['SCRIPT_NAME'] = '/cron.php';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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