[Techtalk] A PHP script in a crontab.

Devdas Bhagat devdas at dvb.homelinux.org
Sat Jan 29 03:02:28 EST 2005


On 28/01/05 23:47 +1100, Sue Stones wrote:
> I have written a PHP script that I want to be executed automatically by 
> using cron.  But the problem is that nothing happens when I run it that 
> way.
> 
> The script runs in a web browser, and works as I want it to, but when I 
> put it in a cron tab, nothing happens.  I can think of 2 possible causes 
> of error.  (1) I am calling it wrong, I have been told by the web hoster 
> that the call statement should be something like this:
> 
> "GET http://www.hostyorkshire.com/scgi-bin/script.php > /dev/null "
> 
> I am not sure what the GET does!  This doesn't work.

If you don't have GET, but you do have access to wget, 
wget http://www.hostyorkshire.com/scgi-bin/script.php -O - > /dev/null

Alternatively, you can call the PHP interpreter directly
/usr/bin/php /local/path/to/php/script.php > /dev/null

(Or you could set MAILTO= in the crontab to achieve the same as 
command > /dev/null2>&1 for all commands in your crontab.

> (2) the other possible cause is that the PHP code won't work if its not 
> executed in a web browser.  Does anyone know if this is so, and what I 
> have to do to make it work?

PHP code is not executed in a web browser. PHP code is executed on the
web server, in response to a request. The server really doesn't care
what application made the request.
 
A common web browser parses and renders the servers response on a screen, 
but it could do anything else with that response data, including nothing
at all.

Devdas Bhagat


More information about the Techtalk mailing list