Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Cron Job does not Run but does Manually


geoffreywalton

Recommended Posts

Here is a tip that may help you keep your hair for a few more years.

 

You set up a cron job and it gives an error such as

 

Parse error</b>:  syntax error, unexpected '{' in

 

Then if you run the same script from the command line it runs perfectly.

 

Naturally enough you are a little confused!!

 

Try running a script containing just this code

 

<?php
echo 'My PHP Version: ' . phpversion();
?>

 

and then run it manually and using cron.

 

In my case with a 1and1 server, cron was runnng version 4.4.9 and the site 5.4.14.

 

The reason for the error, in my case, was that the php command try is not available in the version of php being used by cron.

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

In general, "cron" runs the Linux command line in a very different environment than the webserver provides. Don't count on anything being the same -- explicitly give directories, PHP versions to invoke, etc. Don't rely on default settings on anything being the same between the two -- explicitly give all settings and switches.

 

Another common "gotcha" is that the command line usually does not support URL Query Strings. You need to give any parameters following the PHP file to run, separated by spaces. They can be either positional or varname=value pairs, but the PHP code needs to be modified to read them.

Link to comment
Share on other sites

After contacing my host, 1and1, their explanation of their undocumented feature is as follows:-

 

The version of php used by cron is dependent on the command used in the cron job.

 

For example if you are using /usr/local/bin/php in your cron job it will use PHP 4.

 

To use PHP 5.2 you will use /usr/local/bin/php5 and to use PHP 5.4 you will use /usr/bin/php6.

So, in the unlikely event you get caught be this the secret once again is contact your host!!

 

HTH

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

if you are using /usr/local/bin/php in your cron job it will use PHP 4.

 

To use PHP 5.2 you will use /usr/local/bin/php5

 

to use PHP 5.4 you will use /usr/bin/php6

Nice and intuitive! ;) You'd think they'd offer php52, php53, php54, etc.

Link to comment
Share on other sites

Not really sure they should offer anything other than the same version as the site.

 

Cheers

 

G

Need help installing add ons/contributions, cleaning a hacked site or a bespoke development, check my profile

 

Virus Threat Scanner

My Contributions

Basic install answers.

Click here for Contributions / Add Ons.

UK your site.

Site Move.

Basic design info.

 

For links mentioned in old answers that are no longer here follow this link Useful Threads.

 

If this post was useful, click the Like This button over there ======>>>>>.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...