Set cron job with a PHP script

Discussion in 'Site & Server Administration' started by thuankkk, Sep 1, 2009.

  1. #1
    Say you have a PHP script, and you want that script to execute periodically, e.g every 5 minutes.
    Of course, you can't be online 24/7 to call its URL.

    So, the only thing you should do is set cron job with that PHP script.
    All you need is a server that supports cron.

    You can read about cron at Wikipedia.

    Here are some commands that will execute your php script:
    
    php -q /path/to/script.php
    wget http://example.com/path/to/script.php -o /tmp/output.txt
    lynx http://example.com/path/to/script.php
    
    Code (markup):
    Personally, I recommend you to use lynx, as this makes a real request to your script, just like how you do: paste the URL into web browser, then press enter. Some script may not work properly when being called by php from console.

    Or, you can simply go to www.setcronjob.com, cronless.com, onlinecronjobs.com, etc, and set cron job with your URL. No need to worry about *nix command :)
     
    thuankkk, Sep 1, 2009 IP