Jump to content



Latest News: (loading..)

- - - - -

Cron Job does not Run but does Manually

cron version php version try

  • Please log in to reply
4 replies to this topic

#1 ONLINE   geoffreywalton

geoffreywalton

    Contact me for Support

  • Community Sponsor
  • 8,032 posts
  • Real Name:Geoffrey Walton
  • Gender:Male
  • Location:Norfolk, UK (close to the centre of the universe)

Posted Yesterday, 12:27 PM

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 ======>>>>>.

#2   MrPhil

MrPhil
  • Members
  • 4,127 posts
  • Real Name:Phil
  • Gender:Male

Posted Yesterday, 01:59 PM

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.

#3 ONLINE   geoffreywalton

geoffreywalton

    Contact me for Support

  • Community Sponsor
  • 8,032 posts
  • Real Name:Geoffrey Walton
  • Gender:Male
  • Location:Norfolk, UK (close to the centre of the universe)

Posted Today, 08:35 AM

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 ======>>>>>.

#4   MrPhil

MrPhil
  • Members
  • 4,127 posts
  • Real Name:Phil
  • Gender:Male

Posted Today, 01:59 PM

View Postgeoffreywalton, on 20 May 2013 - 08:35 AM, said:

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.

#5 ONLINE   geoffreywalton

geoffreywalton

    Contact me for Support

  • Community Sponsor
  • 8,032 posts
  • Real Name:Geoffrey Walton
  • Gender:Male
  • Location:Norfolk, UK (close to the centre of the universe)

Posted Today, 10:11 PM

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 ======>>>>>.