3

As stated in Cron.php do not start the cronjobs, the insertion of

$isShellDisabled = true;

will make it work. But what is the real cause for this? Why

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

cannot get the right value?

so be it - manemoi Theodor

3

Looking at cron.php, the objective of that variable is to determine if something can be executed with sh.

    } else if (!$isShellDisabled) {
        $fileName = basename(__FILE__);
        $baseDir = dirname(__FILE__);
        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 &");
        exit;
    }

As you can see this elseif statement has an exit statement. Your script is therefore determining that you are not running windows and that shell_exec isn't disabled, thus you are hitting the exit statement. By forcing the variable to be true you are forcing the script to skip this part of the script.

This raises the question of why the above code isn't functioning as expected when it's not skipped. If I had to guess I would say that it's because of one of the following (in order of likeliness):

  1. The user triggering cron.php doesn't have +x permissions on cron.sh.
  2. The user triggering cron.php doesn't have sh in it's PATH.
  3. The OS that it's running on doesn't have support for something in the command.
  4. The php shell_exec function is disabled in some way other than the ini variable disable_functions (I don't know if this is possible or not).

You could debug this by finding the command that's actually ran by echo'ing out some debug info:

    } else if (!$isShellDisabled) {
        $fileName = basename(__FILE__);
        $baseDir = dirname(__FILE__);
        $cmd = "/bin/sh $baseDir/cron.sh $fileName -mdefault 1 > /dev/null 2>&1 &";
        echo $cmd . PHP_EOL;
        shell_exec($cmd);
        $cmd = "/bin/sh $baseDir/cron.sh $fileName -malways 1 > /dev/null 2>&1 &";
        echo $cmd . PHP_EOL;
        shell_exec($cmd);
        exit;
    }

This will confirm the paths are correct and as expected. Then running the resulting commands to see what happens (you'll get better debug info by removing > /dev/null 2>&1 & from the end).

|improve this answer|||||
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

|improve this answer|||||

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.