Magento provides two cron scripts in its root directory, cron.php and cron.sh.
Which one is the better to run and why?
It would be best to run cron.sh
As of Magento EE 1.13.x and CE 1.8.x, the cron mechanics have changed where Magento has introduced a new scheduling mode function.
There are 2 available modes: 1. default - runs scheduled crons. 2. always - As the name says these tasks will unconditionally be executed every time cron is triggered and don’t need an explicitly defined schedules.
Basically cron.php being called without any parameters uses shell_exec to execute two processes of cron.sh. Each with a different parameter (“default” or “always”). Cron.sh in turn passes this parameter back to cron.php which then executes the cron. Internally Magento uses its event infrastructure to process the two modes by dispatching events with the names “default” and “always”. Mage_Cron then implements two observer methods.
Looking at cron.php, you will notice the usage of the PHP function shell_exec. Apart from being a security concern, the function can return NULL both when an error occurs or the program produces no output. It is not possible to detect execution failures using this function. This means that at any given point when your script / code fails due to an error, the following happens: 1. The cronjob becomes stale, 2. No error is recorded, 3. and no one knows that any of this has happened.
To overcome this, the following cronjob's should be added:
*/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
This will ensure that the process modes will always run without using the fallback PHP function shell_exec and that the cron should not become stale as an exception is thrown if an error does occur.
www-data
would change to whatever user runs web server processes. Also worth noting that for many CPanel/WHM hosting setups, shell_exec()
is going to be disabled.
*/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
and these commands give "command not found" error by nupur walia
*/5 * * * * /bin/sh /path/to/magento/cron.sh cron.php -m=default
Commented
Oct 29, 2015 at 10:28