Page 1 of 1

PHP and Cron Jobs

Posted: Tue Mar 08, 2011 7:33 pm
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

Re: PHP and Cron Jobs

Posted: Tue Mar 08, 2011 7:44 pm
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.

Re: PHP and Cron Jobs

Posted: Tue Mar 08, 2011 7:48 pm
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.