1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Run PHP script from cron job?

Discussion in 'Site & Server Administration' started by Kerosene, Oct 30, 2008.

  1. #1
    Is it possible to set up a cron job that will execute a php script?

    And if so, what are the commands to do it?
     
    Kerosene, Oct 30, 2008 IP
  2. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #2
    which server you are using Linux or Windows and control panel??

    to run a cron job you just need to point the cron the the script you are trying to execute..
     
    Freewebspace, Oct 30, 2008 IP
  3. Kerosene

    Kerosene Alpha & Omega™ Staff

    Messages:
    11,366
    Likes Received:
    575
    Best Answers:
    4
    Trophy Points:
    385
    #3
    Unix running Apache, and I'm using the standard cron manager in cPanel

    I'm trying this, if you don't hear back from me, then it's working :p

    php -q /home/blabla/public_html/blabla/cron.php
     
    Kerosene, Oct 30, 2008 IP
  4. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #4
    There is no $PATH in the crontab so you will need the full path to php. Something like /usr/local/bin/php.

    Alternatively, you can use a shebang line as the first line of your script that looks like this:
    #!/usr/local/bin/php
    Code (markup):
    The only other thing to be careful of is that the cron jobs will run as the user whose crontab they are in. If this user is root then you will want to write dropping permissions into your cron job. If it's running as you then your permissions will probably be fine. If you need it to run as the same user that Apache runs as then you will need to use su.
    sudo su www-data -c "/usr/local/bin/php /path/to/php/script/here.php"
    Code (markup):
     
    Ladadadada, Oct 31, 2008 IP
  5. diligenthost

    diligenthost Peon

    Messages:
    685
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You shouldn't need the full path to PHP, it should work fine without it. You do however need the full path to the script, which "/home/blabla/public_html/blabla/cron.php" is already set!
     
    diligenthost, Oct 31, 2008 IP
  6. adbox

    adbox Well-Known Member

    Messages:
    906
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    155
    Digital Goods:
    1
    #6
    adbox, Jan 30, 2010 IP