Method 1: Run a script using php from crontab
Just as you call your shell script (as shown in our crontab 15 example article), use the php executable and call the PHP script from your crontab, as shown below.
To run myscript.php every 1 hour, follow these steps:
crontab -e
00 * * * * /usr/local/bin/php /home/john/myscript.php
Method 2. Run php script using url from crontab
If your php script can be invoked using a url, you can use lynx or curl or wget to configure your crontab as shown below.
The following script runs a php script (every hour), invoking the URL using the lynx text browser. The Lynx text browser, by default, opens the URL interactively. However, as shown below, the -dump option in the lynx command dumps the output of the URL to standard output.
00 * * * * lynx -dump http://www.thegeekstuff.com/myscript.php
The following script runs a php script (every 5 minutes), invoking the URL using CURL. Curl displays output in standard output by default. Using the "curl -o" parameter, you can also output the output of your script to a temporary file, as shown below.
*/5 * * * * /usr/bin/curl -o temp.txt http://www.thegeekstuff.com/myscript.php
The following script runs a php script (every 10 minutes), invoking the URL using WGET. The -q option indicates pretty mode. "-O temp.txt" indicates that the output will be sent to a temporary file.
*/10 * * * * /usr/bin/wget -q -O temp.txt http://www.thegeekstuff.com/myscript.php