[Techtalk] A PHP script in a crontab.

Paul W list3 at truswan.com
Sat Jan 29 07:11:47 EST 2005


Sue,

I do this all the time on a number of servers. You need to 
make sure the command line version of PHP is installed on 
your server. Once that is done, you would use, as mentioned 
earlier in this thread, "php scriptname.php" or "php-cgi 
scriptname.php" (depending on which version of php cli is 
installed). The scripts I use on the command line don't 
output any html, so there's no confusion about that. In my 
opinion, it is going to be better if you use scripts that 
accomplish a task but have no html, echo or print statements 
in them unless you want to redirect output to a file. For 
example: php scriptname.php > filename.

Here is a good tutorial on php cli: 
www.phpfreaks.com/tutorials/86/0.php

Paul Wear

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.
> 
> (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?
> 


More information about the Techtalk mailing list