Entry
How do I run a PHP script as a cron job?
Jan 2nd, 2002 23:33
Scott Whetzel, Chris Kings-Lynne,
To run a PHP script as a cron job.
1. Compile PHP independently of Apache into a 'php' executable.
2. Move the executable into, say, /usr/local/bin.
3. Write a PHP (shell) script like this (I'd name this 'cron.sh'):
#!/usr/local/bin/php -q
<?php
echo "This is running as a cronjob!"
?>
4. Add cron.sh to your crontab.
Easy.
****ADDITIONAL NOTES*****
For those who can not do step 1 above, there is the another option.
Invoke the text based browser lynx to access/execute a web page. Just
add the following crontab entry:
* * * * * /lynxpath/lynx -dump url > /dev/null
below is an example
* * * * * /usr/local/bin/lynx -dump
http://www.allegracorp.com/emailtest.php > /dev/null
Notes for above crontab entry:
1. Above is all one line.
2. lynx path may be /usr/local/bin or /usr/bin or something else.
3. -dump or -source can be used interchangeably. They exit lynx after
accessing url
4. Doesn't seem to matter if quotes are around url or not.
5. /dev/null sends screen output to bit bucket so you don't fill up
mail account.
Hope this helps.