3

All cron jobs were scheduled but not executed.

Googled it lot but no help. I have checked this too.

Then found this link

As it described I have added this line $isShellDisabled = true; and cron start executing.

$disabledFuncs = explode(',', ini_get('disable_functions'));
$isShellDisabled = is_array($disabledFuncs) ? in_array('shell_exec', $disabledFuncs) : true;
$isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;
$isShellDisabled = true; //newly added line

Question

Is it OK to add this line?

I am running site in "ventraip" hosting provider.

2

3 Answers 3

3

Modifying core files is not a recommended practice at all. Luckily there is another solution, but first let me explain what this line is doing:

The three lines before try to figure out if PHP is allowed to execute shell commands and set $isShellDisabled = true if not.

If it is false, cron.php will start two cron.sh processes in the background

cron.sh /path/to/cron.php -mdefault
cron.sh /path/to/cron.php -malways

cron.sh in turn, runs cron.php (with the same arguments) if it doesn't find a running cron.php process. At least in theory, apparently checking for a running process does not work if the process has been spawned from cron.php as described above.

Now, if $isShellDisabled is true, this is not possible and cron.php will run in both modes ("default" and "always") one after another.

Solution

You can leave out the first step of all this and set up your crontab directly with two jobs:

cron.sh cron.php -mdefault
cron.sh cron.php -malways

(with full path to cron.sh and cron.php) This way you'll have a working check if there is already a running process, but you cannot specify the path to the PHP binary to be used.

If that's important, use this instead:

/path/to/php cron.php -mdefault
/path/to/php cron.php -malways
1
  • 1
    Thank you @fschmengler. I will try your solution tomorrow. Sep 20, 2016 at 7:07
1

The issue could be magento_root/cron.php not set in server crontab. We need to add this file in crontab so it worked for us as follow.

# crontab -l (this command will list all the Cron jobs in Crontab)

There should be an entry for magento_root/cron.php file. If not, we need to add this file because this file is responsible for initiating your Magento Cron jobs. So we need to edit the Crontab as follow.

# crontab -e

Add the following statement in the file and close after saving it.

*/5 * * * * wget -O /dev/null -q path_to_magento_root/cron.php > /dev/null

For more information, visit this link

0

Faced the same issue when setting up a cronjob in Kubernetes. Both cron.sh and cron.php spawn background processes, marked by the & at the end of the commands.

So the scripts immediately return exit code 0, which causes to shutdown the Kubernetes container, before the cronjobs actually ran through completely.

Cron.php

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 &");

My solution
I wanted to keep all magento core files untouched, so I decided to check periodically if there is still a cron.php process running.

This is my entrypoint for the cronjob container:

#!/bin/bash

# run cron
$HOME/cron.sh

# wait until cron background processes are finished
while [ -n "`pgrep -f 'cron\.php'`" ]; do
    echo -n '.'
    sleep 10
done

exit 0

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.