Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I run a PHP script from cron?

PHP

How do I run a PHP script from cron?

by  bgarlock  Posted    (Edited  )
Have you ever written a PHP script for a webpage, and wanted it to run at a specified time? When you compile PHP as a DSO into apache, you have to use a browser to run the script. I often do this to query databases, and import data periodically to another database, using PHP. To automate the task, I use cron to run the PHP script. Here is the format that you need to use in your crontab:

0 6 * * * TERM=xterm; export TERM; /usr/bin/lynx -source "http://www.server.com/path/to/script.php" 1>/dev/null 2>&1

This would have the same effect as the user bringing the PHP script up in a browser, if all the script did was to perform actions, without any required user input.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top