PHP script for a CRON job

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • canstocker
    Junior Member
    • Mar 2004
    • 26

    PHP script for a CRON job

    Hello everyone,

    Is it possible to create a CRON job that executes a php script every night?

    Dan.
  • Denny
    Junior Member
    • Jun 2006
    • 12

    #2
    I've seen several ways to do it, but this is one of the cron jobs I run:

    Code:
    wget -q http://yourdomain.com/script.php
    You can add GET variables to the end of it also:

    Code:
    wget -q http://yourdomain.com/script.php?a=asfsfsd
    This obviously won't work if the script is not somewhere in your public_html/ directory. I think there are ways to do it if that is the case, but I'm really not an expert with cron.
    Denny Cave
    Cave Interactive Media
    http://caveim.com

    Comment

    • Denny
      Junior Member
      • Jun 2006
      • 12

      #3
      Also, just a thought, but if this IS in your public_html and you don't want just anyone to be able to run the script, create a password in your script:
      Code:
      if(isset($_GET['password']))
      {
        if($_GET['password'] == "YOURPASSWORD")
        {
            //code to execute
        }
      }
      And then put the password in the cron job:

      Code:
      wget -q http://yourdomain.com/script.php?password=YOURPASSWORD
      Denny Cave
      Cave Interactive Media
      http://caveim.com

      Comment

      • AndrewT
        Administrator
        • Mar 2004
        • 3653

        #4
        Or use /usr/local/bin/php /home/username/path/to/script.php - this just leaves out the unnecessary HTTP middle man.

        Comment

        • Denny
          Junior Member
          • Jun 2006
          • 12

          #5
          That's the other one I was thinking of... couldn't remember it off hand and also I don't think I'd ever gotten it to work. Probably because I was using php /path/to/script.php instead of /usr/local/bin/php. Thanks for clearing that up.
          Denny Cave
          Cave Interactive Media
          http://caveim.com

          Comment

          Working...