views:

189

answers:

3

So I have a cronjob which executes a PHP script like so:

0 0 * * * /usr/local/bin/php -f /home/mysite/mysite.com/cronjobs/renewal_email.php

If I issue the same command from the command line it runs without error and running with the l flag shows no syntax errors. However cron emails the following:

Parse error: syntax error, unexpected T_OBJECT_OPERATOR

The line in question is

$courses[$t->CourseNumber] = $t->course()->CourseName;

Does this limited amount of info raise any red flags? Anyone see why this should happen under cron but not from the command line?

TIA!

JG

// Edit to add DreamHost support response. Script is working with this change.

The default version of PHP on the server is PHP4. This is because the server uses the PATH settings rather than the Apache to specify which version is run. The path for PHP4 /usr/local/bin/php comes before the PHP5 path /usr/local/php5/bin/php so it always runs first when you type php from the shell.

To run PHP5 from the shell you need to specify the entire path:

/usr/local/php5/bin/php --version

The cron user will not use your .bash_profile path so you would need to specify the full path to PHP5 in each cron job.

+1  A: 

I would say youre using two different versions of PHP. does running which php from the command line produce a different path than the one you are using in the cron tab?

prodigitalson
+1  A: 

Hm. The error message sounds like you're running a PHP5 script on a PHP4 interpreter. However, if you use the exact same path to the PHP binary, I can't see how this could happen.

Can you have the cron job do a phpinfo() and see what the output is?

For PHP 4, you'd have to rewrite the instruction:

$temp = $t->course(); 
$courses[$t->CourseNumber] = $temp->CourseName;
Pekka
Yes, Dreamhost has CLI version PHP 4.4.8 and PHP Version 5.2.6 otherwise. Anything to be done about this? Thanks.
jerrygarciuh
See my edited answer.
Pekka
@jerry: change your php version in your shell profile or use the full path in your tab.
prodigitalson
So DreamHost support responded re the version issue and my script is now running successfully! Yay. Thank you Pekka for the help!! I will add DH's response to my post.
jerrygarciuh
A: 

That error means that your variable doesn't contain an object. Try var_dump:ing it while running the cron job.

chelmertz
I don't think that is correct. It's a parse error. The script is not running and instantiating objects. It is failing to compile.
jerrygarciuh