Web Hosting Talk







View Full Version : cron tasks problem!


Xigna Hosting
09-11-2005, 10:53 AM
When I run a PHP file as a cron task I get this report by email:

/home/****/public_html/dailybackup.php: line 1: ?php: No such file or directory
/home/****/public_html/dailybackup.php: line 9: syntax error near unexpected token `;'
/home/****/public_html/dailybackup.php: line 9: `session_start();'

How do I fix this?

I blurred out my username just for security.

Luke

jetson
09-11-2005, 11:10 AM
try to specify the full command to run the program eg:

/path/to/php yopurphpscript.php

(try typing it in on the command line to see if it works right, then put it in a crontab)

or you can add a sha-bang to the php script-like perl/tcl/etc

#!/usr/bin/php

or wherever your php binary is stored, try

which php

extras
09-11-2005, 09:02 PM
In addition to shebang + executable permission (often 755) or
invoking by php command, you may need to cd into the directory of the script.

34 12 * * * cd /home/****/public_html; ./dailybackup.php

34 12 * * * cd /home/****/public_html; /usr/local.bin/php -q dailybackup.php

You may need more than that if the script isn't designed for a cronjob ...

Burhan
09-12-2005, 02:33 AM
You have a few problems with your script.

1. It has syntax errors

2. You can't use sessions when running the script on the command line. Sessions (just like $_GET, $_POST, $_COOKIE, etc.) are only available when the script is requested via a URL.

3. If your script depends on the use of sessions (I can't imagine why since its a cron task), you must call it from a browser (like lynx).