Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
February 07, 2012, 09:30:13 PM

Pages: [1]   Go Down
  Print  
Author Topic: Problem setting up cron job with php5  (Read 4424 times)
offer13
Newbie
*
Offline Offline

Posts: 5


« on: June 05, 2009, 09:02:38 AM »

HI,

My new to all that cron job stuff so here's my problem

I need to setup a cron job for a file called cron.php 

here's the command line I have /usr/local/php5/bin/php -f /home/username/public_html/dir/autoresponder/admin/cron/cron.php

But it doesn't seem to work because I didn't receive email from the autoresponder I'm trying to setup

Eric
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5080



« Reply #1 on: June 05, 2009, 10:16:26 AM »

1. You've confirmed that /usr/local/php5/bin/php is the correct location of the PHP 5 parser on your server?

2. The -f flag appears to be unnecessary in this case. If you use any command line parameters along with -f, you need to use the -- flag.

3. You might consider using the -q flag to silence page header output.

4. Something easily overlooked: the environment  you're running in is much different than when you're running from a Web browser. Here, you are running on the Linux command line, and there's a lot of stuff set up by the Apache server that you don't get. Make no assumptions about your environment settings or even what directory you are starting in. Be very explicit about full paths and settings.
Logged

rick1m
Newbie
*
Offline Offline

Posts: 3


WWW
« Reply #2 on: August 01, 2009, 06:21:10 AM »

You may also want to check the permission on the file. I think it should be something like 766. You can change permissions in your file manager from cpanel. Someone from lunarpages support even suggested to use .php5 for the file extension. One amateur mistakes i made when i first started using cron was including the run time parameters on the command line. Stop laughing everyone: at least i can admit my dumb mistakes LOL.   * * * * * * usr/bin/php5/ etc  i kept getting file not find or no input file, something to those effects. Personally, i think the advanced tab is the better solution  to setup the cron job. Hope this helped! rick
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5080



« Reply #3 on: August 01, 2009, 07:21:58 AM »

644 is fine for a PHP (.php) file. LP does not require it to be 'executable' (755). 766 is bad on several points: 1) you don't need owner's execute bit on, 2) you don't want to give 'group' and 'world/others' write permission. I don't know if suPHP is involved from the command line, but if it is, it may not even let you run the script (world writable).
Logged

lexhair
Galactic Royalty
*****
Offline Offline

Posts: 402


« Reply #4 on: September 04, 2009, 08:50:25 AM »

I'm currently using php 4.4.9 and I've got about 15 or so crons set up. Am I going to have to fix each cron command on the cron tab if I upgrade to php 5?
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5080



« Reply #5 on: September 04, 2009, 10:05:09 AM »

No. By default, cron jobs using just "php" will continue to use PHP 4. Cron jobs and your web site are two different things. If you need PHP 5 functions in your cron job, you will then need to fix each command. Otherwise, you can leave it as-is.
Logged

lexhair
Galactic Royalty
*****
Offline Offline

Posts: 402


« Reply #6 on: September 04, 2009, 11:19:01 AM »

No. By default, cron jobs using just "php" will continue to use PHP 4. Cron jobs and your web site are two different things. If you need PHP 5 functions in your cron job, you will then need to fix each command. Otherwise, you can leave it as-is.
Beautifully simple and concise answer. Thanks!
Logged
MarkCale aka Madscape
Spaceship Navigator
*****
Offline Offline

Posts: 78



« Reply #7 on: October 26, 2009, 11:46:15 PM »

you can also setup cURL to run your PHP crons due to the fact of the commands you are trying to use is strictly PHP4 commands only.
Logged

Forum Lurker and Former Galactic Tekkie, mostly a jack of trades and master of none!  Mark H. Cale
automania
Newbie
*
Offline Offline

Posts: 1


« Reply #8 on: November 08, 2009, 07:05:51 AM »

Hi everybody,

I had the same problem (I had programmed a lot of php5 classes and functions and then I need some of them to be executed by a cron job).

I asked for support to LP, and then I tested the solution they gave to me. It worked!. The solution is:

Just set your cron job as following:

/usr/local/php5/bin/php -q /home/USERNAME/public_html/FOLDER/myPHP5File.php

Just replace USERNAME, FOLDER and myPHP5File.php with suitable info.
Logged
MarkCale aka Madscape
Spaceship Navigator
*****
Offline Offline

Posts: 78



« Reply #9 on: November 08, 2009, 02:14:29 PM »

Hi everybody,

I had the same problem (I had programmed a lot of php5 classes and functions and then I need some of them to be executed by a cron job).

I asked for support to LP, and then I tested the solution they gave to me. It worked!. The solution is:

Just set your cron job as following:

/usr/local/php5/bin/php -q /home/USERNAME/public_html/FOLDER/myPHP5File.php

Just replace USERNAME, FOLDER and myPHP5File.php with suitable info.

This particular issue has been discussed before but to also provide further clarification on PHP5 cron jobs. The shared servers use a dual PHP configuration which enables you to switch from version 4 to version 5 and vise-versa.  Try to remember that cron jobs are going to use the version 4 commands, since the server is not PHP5 dominant. You only need to use cURL or HTML to run a PHP5 cron job as well.

E.G. I have a cron job in PHP5 I need to run so I decided to add in the HTML path which would be /usr/local/php5/bin/php -q /home/USERNAME/public_html/FOLDER/myPHP5File.php as provided by automania or use the cURL command. I would always suggest using the example provided by automania as it is the easiest and providing the direct path the cron job insures no issues later down the line.
Logged

Forum Lurker and Former Galactic Tekkie, mostly a jack of trades and master of none!  Mark H. Cale
lexhair
Galactic Royalty
*****
Offline Offline

Posts: 402


« Reply #10 on: November 09, 2009, 09:07:18 AM »

The obvious follow up question is why is PHP4 still around on the shared servers?
Logged
MrPhil
Berserker Poster
*****
Offline Offline

Posts: 5080



« Reply #11 on: November 09, 2009, 11:26:41 AM »

There are applications still out there that can't use PHP 5. They might use long array names (for instance, $HTTP_POST_VARS instead of $_POST) or use some other obsolete functions or facilities, such as deprecated "ereg" functions and certain session functions. Anyway, it does no harm to continue to offer PHP 4 for the time being. Users have to realize that there is little or no support for it (a security problem might not get fixed), so they should be using this time to upgrade their applications to work with PHP 5 anyway (and PHP 6 is on the horizon). Fortunately, it's not rocket science to eliminate register global variables, long array names, ereg and session functions, etc., just a bit of work. Eventually, LP will have to withdraw PHP 4 due to lack of support, and users who haven't bothered to upgrade their applications will have to scramble.

Add: LP could smooth the transition by first making PHP 5 the default version, and requiring users to manually switch on PHP 4 in .htaccess (the opposite of what's done today). That way, users wouldn't be stranded by this wakeup call, but could turn on PHP 4 while they patch their code, much as they do today if they still use register global variables (enable it in php.ini). Eventually, PHP 4 would entirely go away.
« Last Edit: November 09, 2009, 11:34:44 AM by MrPhil » Logged

lexhair
Galactic Royalty
*****
Offline Offline

Posts: 402


« Reply #12 on: November 09, 2009, 12:36:51 PM »

Add: LP could smooth the transition by first making PHP 5 the default version, and requiring users to manually switch on PHP 4 in .htaccess (the opposite of what's done today). That way, users wouldn't be stranded by this wakeup call, but could turn on PHP 4 while they patch their code, much as they do today if they still use register global variables (enable it in php.ini). Eventually, PHP 4 would entirely go away.
This gets a +1. Maybe even a +2.
Logged
lexhair
Galactic Royalty
*****
Offline Offline

Posts: 402


« Reply #13 on: November 10, 2009, 12:05:29 PM »

you can also setup cURL to run your PHP crons due to the fact of the commands you are trying to use is strictly PHP4 commands only.
Not a bad suggestion either. Configuring cUrl crons isn't too hard.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to: