Saturday, October 11, 2014

Using Cron Job to process PHP scripts



Using Cron Job to process PHP scripts.
For example, we have test.php and want to run it  every day using cron job.
1) test.php
<?php
    echo '<h1> This is  a test for cron job</h1>';
?>

 2) Create a shell script test.sh
#! /bin/sh
#wget -q --no-check-certificate -O- "http://swf.site40.net/crontest/test.php"
php test.php
3) run following in shell to make test.sh executable
chmod +x test.sh
4)  The reason we want to use php instead of wget is that we do want outside people access test.php
Set up .htaccess to Deny from all in the directory of test.sh
<Files "*">
    Order deny, allow
    Deny from all
</Files>

5) crontab -e
30 23 * * * /home/jiansenl/crontest/test.sh
each night 23:30pm to  run test.sh
6) crontab -l
list cron jobs.
Video: Using Cron Job to process PHP scripts

1 comment:

  1. hello. thanks for the article.
    i have tried this on a suse leap 42 without sucess.

    php gives me error
    im trying to read a php page wich reads a series of parameters and stores them to a mysql db.

    ReplyDelete