Cron


#1

I have a script running via cron this way:
/usr/bin/curl http://www.bidwindrive.com/update_records.php
It runs OK, but it seems to be choppy. (It’s running a timer BTW.)

I have tried to run it this way:
/usr/local/php5/bin/php /home/paulhawkins/www/update_records.php

But it results in “not found” type errors. The online chat help suggested using shell - so I tried that. If I login, do nothing else, and run the command, I get the errors. If I first do “cd www” then run the command, it works fine.

Wassup?


#2

Can you post the errors? Might be able to figure something out then.

Because everyone has an opinion.


#3

Warning: require_once(common/sitesetting.php): failed to open stream: No such file or directory in /home/paulhawkins/www/config/connect.php on line 7

Fatal error: require_once(): Failed opening required ‘common/sitesetting.php’ (include_path=’.:/usr/local/php5/lib/php:/usr/local/lib/php’) in /home/paulhawkins/www/config/connect.php on line 7


#4

Here’s part of your problem. You’re not providing an absolute path. Try defining the full path instead, perhaps in a variable you can refer back to?

Because everyone has an opinion.


#5

When a PHP script is run on the web (ie invoked by Apache), the current working directory is set to the script’s directory. Because of this PHP scripts typically use relative paths to load libraries and settings.

In contrast Cron jobs are always started with the working directory set to the user’s home directory. So your Cronjob script will need to change the directory before running the script. Like this:

cd www
/usr/local/php5/bin/php update_records.php