Welcome to WebmasterWorld Guest from

Forum Moderators: bakedjake

Message Too Old, No Replies

Cron Job PHP Problem

...what's wrong?

4:48 pm on Sep 3, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Oct 4, 2004
votes: 0

Hi guys,

I set up a cron job to execute a PHP script that writes a file and it isn't working. I can't tell if the cron job itself or the PHP script is failing.

If I type this on the command line it works fine:

php /usr/www/myname/mysite/jobs/main.php

...and here is my crontab entry (for testing):

* * * * * php /usr/www/myname/mysite/jobs/main.php

...which seems fine.

One thing I can think of is the path to the file in the PHP code. I gave it the full path like so:


Since it's getting called in the crontab maybe I have to do something different? What about the permissions for the main.php file, does that need anything special? Like I said, it works on the command line so I don't know what I could be doing wrong.


9:00 pm on Sept 4, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 28, 2002
votes: 0

Hi Emperor,

just two things to check first:
-1- the crontab-user may not have the same environment as you have when testing and running the /your/path/to/php command, so you would be on the safe side to specify the full path of the php interpreter in the crontab.
-2- the permissions of the main.php file may be important or not, depending on the file-ownership of the main.php (and the directory above) and its relation to the crontab-user.


4:38 pm on Sept 7, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:May 28, 2004
votes: 0

Yeah, most likely its a path issue, try adding the path to php and add the -q switch. Example:

/usr/bin/php -q /usr/www/myname/mysite/jobs/main.php

3:44 pm on Sept 20, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 8, 2002
votes: 0

or just run the script with:

lynx [localhost...]


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members