PHP and Cron Jobs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shags_j
Forum Newbie
Posts: 9
Joined: Sun Aug 22, 2010 9:55 pm

PHP and Cron Jobs

Post by shags_j »

Hi guys,

I am having an issue with a cron job I setup. It runs a php file. The php file runs fine if I execute it through a browser.

In the php file I reference a .txt file held on the server. I do a file_exists and check for existence. When I run this through the cron it can't find the file however when I run through the browser it finds it and works fine.

Any ideas on how I should reference the path to the file (i assume this is the issue).

Cheers,

J
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP and Cron Jobs

Post by Jonah Bron »

In your cron configuration, instead of running this:

Code: Select all

$ php /path/to/my/php/file.php
run this:

Code: Select all

$ cd /path/to/my/php
$ php file.php
The issue is the relative path. It's being referenced from the wrong place.
shags_j
Forum Newbie
Posts: 9
Joined: Sun Aug 22, 2010 9:55 pm

Re: PHP and Cron Jobs

Post by shags_j »

Problem is it's though a hosted webserver and I can't really run much in the way of cron commands. They only have a single line for command.
Post Reply