Magento – Cronjobs Magento 1.9.2.2 – Is it possible to have Cron.sh call Cron.php by /usr/php/54/usr/bin/php

croncrontaberrormagento-1.9

I have spent about two weeks on and off trying to figure this out. I have honestly tried so many different things and configurations, I don't remember all of them anymore. Essentially I can't get the Magento cronjobs to function correctly.

I have no experience with Cron Jobs until now, so there has been a steep learning curve so far. I have Bluehost for a hosting company with a shared server, so no direct command line root access as far as I know, just Cpanel. After going back and forth with the hosting company and trying different methods, this at least seems to be correctly launching the Magento cronjobs.

*/5 * * * * /bin/sh /MyDomainUserName/public_html/cron.sh 

I spent a long time trying to work with AoeScheduler but couldn't ever get it to successfully produce a heartbeat task and all jobs always stayed pending. I gave up on it and got Cron Doctor for now.

The tasks sort of work, they launch and I get through a couple and then it gets "stuck" – so far every time on "Captcha Delete Expired Images".

Once this happens, every 5 minutes I get an email from Cron Daemon saying

"Status 500 Internal Server Error Content type: text/html"

And in my error_log I get this:

Jan-2016 00:10:02] PHP Parse error:  syntax error, unexpected T_FUNCTION in /MyDomainSpecifics/public_html/app/code/core/Mage/Core/Helper/Abstract.php on line 240"

Once I use Cron Doctor to delete all of the Magento jobs, it goes around to the next 5 minutes and I get a clean Cron Daemon email that just says "Content type: text/html" – with no new errors in error_log, and the jobs start running again, same ones, and then repeats getting stuck like above.

I have tried leaving the "Magento Cron (Scheduled Tasks) - all the times are in minutes" – on the default settings of 15,20,15,10,60,600 and I have tried settings recommended in other posts like 60,1,60,120,120,120 and 15,60,60, 120, 120, 3000.

I really feel like I don't have a handle on this and don't know what to do at this point. I have always been able to figure out how to do something, one way or another but I am lost on this. I feel like I have gotten closer, but being close, doesn't do me any good.

I'm pretty sure that the 500 error is because the jobs back up, to many in index or whatever but I don't know how to fix this.

I have also used PHPadmin to go in and clear the cron_schedule directly, among about a million other solutions I have tried. None solving my problem. I may come back and edit this as I think of other things I have tried, or post them as a response. I just want to get this up and get any input I can.

edit… I also already edited my Cron.php file to add the line$isShellDisabled = true; AFTER the line $isShellDisabled = (stripos(PHP_OS, 'win') === false) ? $isShellDisabled : true;

Another avenue I explored was the time zone issue some mentioned. My server is on USA/MDT and we are USA/EST although I couldn't think of anywhere to really apply this knowledge since I have cronjob running every 5 minutes and not at a specific time. I did change the php.ini file line: date.timezone = "America/Denver"; to date.timezone = "America/New_York";

Any and all help would be greatly appreciated!

My question was marked:

This question already has an answer here:

Cron error on line 240 from Mage/Core/Helper/Abstract.php

I had already seen this answer before but couldn't figure out how it applied to my situation. From my CronJobs in Cpanel, I am running cron.sh not Cron.php. So my cron.php is being run directly within my server from cron.sh if I understand this correctly, which I may not. So I am not sure where I could change php to php55 in the command line? Also my server is running php version 5.4 not 5.2 as in the question. Maybe this is the same issue, but I had already spoken to my host and they said my php and cronjobs were configured correctly on their end.

The contents of cron.sh essentially are below:

# Open Software License (OSL 3.0)
#

# location of the php binary
if [ ! "$1" = "" ] ; then
    CRONSCRIPT=$1
else
    CRONSCRIPT=cron.php
fi

MODE=""
if [ ! "$2" = "" ] ; then
    MODE=" $2"
fi

PHP_BIN=`which php`

# absolute path to magento installation
INSTALLDIR=`echo $0 | sed 's/cron\.sh//g'`

#   prepend the intallation path if not given an absolute path
if [ "$INSTALLDIR" != "" -a "`expr index $CRONSCRIPT /`" != "1" ];then
    if ! ps auxwww | grep "$INSTALLDIR$CRONSCRIPT$MODE" | grep -v grep 1>/dev/null 2>/dev/null ; then
        $PHP_BIN $INSTALLDIR$CRONSCRIPT$MODE &
    fi
else
    if  ! ps auxwww | grep "$CRONSCRIPT$MODE" | grep -v grep | grep -v cron.sh 1>/dev/null 2>/dev/null ; then
        $PHP_BIN $CRONSCRIPT$MODE &
    fi
fi

****EDIT/UPDATE****
I spoke again with Bluehost customer support and inquired about the PHP environment that Cron is running in. Below is the most important parts of our conversation… I am not sure how to directly apply this to the Magento Crons, any help would really be appreciated.

BlueHost:
Notice: Be aware that this only modifies your ~/public_html/php.ini file. If you apply these changes, please confirm that your other php.ini files are up-to-date for the appropriate version of PHP you're using. We highly suggest using the "Single php.ini" option for your desired version of PHP, to ensure that the proper php.ini is being applied for your site's software. If you choose to use PHP 5.4, you'll want to make sure your crons use "/usr/php/54/usr/bin/php" instead, as otherwise it will use PHP 5.2.

Me: How would I implement this specifically for my issue?

Bluehost:
Well, basically to implement that you would just replace any instances of the php command in your cron with /usr/php/54/usr/bin/php instead, so that it runs that command using php 5.4. That said, we don't provide any technical support for crons beyond confirming that you're running.

Me:
I am running a .sh file from my cronjobs – which then directly runs the php file within the server environment. wouldn't this already by default be 5.4?

Bluehost:
No, it would be 5.2, unless the sh file also includes rules to run it as 5.4

Best Answer

Just edit your cron.sh file

Find:

PHP_BIN=`which php`

And replace with:

PHP_BIN='/usr/php/56/bin/php'

(I'm using php 5.6)

I have tested and it worked for me. I'm using hostmonster.com service, default is PHP 5.2 and I have switched to PHP 5.6 in CPANEL.

The path to your PHP 5.6 executable might be different on another hoster, ask their support if you don't find it.

Related Topic