faqts : Computers : Programming : Languages : PHP : Common Problems : Tips and Tricks

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

106 of 131 people (81%) answered Yes
Recently 8 of 10 people (80%) answered Yes

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.