[Techtalk] A PHP script in a crontab.
Jaroslaw Fedevych (UALUG
jaroslaw at linux.org.ua
Sat Jan 29 00:19:15 EST 2005
On Fri, Jan 28, 2005 at 11:47:17PM +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 "
Thanks, really, I have never before laughed *that* loud. At your web hoster,
of course, who deserves to be given "luser of the month" award.
What you *really* need is calling your script as you would do that from
command line. There is no such command as GET. There *may* be a command
version of PHP though, which you may run. Like "php
/filesystem/path/to/your/script.php > /dev/null" or, if the script
outputs some diagnostics you'd like not to lose,
"php /filesystem/path/to/your/script.php | mail -s "Diagnostics from my PHP script" somewhere at somehost.domain".
Please not that you lose your $_GET (canonically you should, but see
below) and $_POST arrays when the script is invoked; you get "normal"
$ARGV instead. (In fact, from some version PHP does make $_GET equal
to $ARGV, in order that scripts that do not distinguish calling method
might still work)
>
> I am not sure what the GET does! This doesn't work.
>
This is HTTP protocol command, not a shell command. cron doesn't
talk HTTP.
> (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?
>
Check if your script relies on anything from $_SERVER, as this may be
the source of incompatibilities.
--
X Windows: It could be worse, but it'll take time.
More information about the Techtalk
mailing list