I want to run a php code every 1 hour

Discussion in 'PHP' started by BinaryShadow, Mar 24, 2010.

  1. #1
    well, i want to run a curl script every 1 hour,can i do it hidden serverside without anyone accessing the page?
     
    BinaryShadow, Mar 24, 2010 IP
  2. lvtim

    lvtim Well-Known Member

    Messages:
    291
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #2
    You use cron instead, if you web hosting provider allows you that ability.
     
    lvtim, Mar 24, 2010 IP
  3. BinaryShadow

    BinaryShadow Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    no but i want to do it with php,cant i do it?
     
    BinaryShadow, Mar 24, 2010 IP
  4. foxbsd

    foxbsd Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    1. crontab -e
    2. * */1 * * * php /home/tom/abc.php

    understand ?
     
    foxbsd, Mar 24, 2010 IP
  5. BinaryShadow

    BinaryShadow Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no i cant get it :(
     
    BinaryShadow, Mar 24, 2010 IP
  6. lvtim

    lvtim Well-Known Member

    Messages:
    291
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #6
    In other words, what he's trying to say is that you set up cron to run your php script every hour. The setup example is like what foxbsd said. Do more reading on what a server cron does so you'll understand more.
     
    lvtim, Mar 24, 2010 IP
  7. BinaryShadow

    BinaryShadow Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    cant it be done with php only?
     
    BinaryShadow, Mar 25, 2010 IP
  8. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #8
    Without cron set up on your server there are two methods.
    1) You can setup external scheduler somewhere else and call your script from there via http request. Or call that manualy every hour.
    2) have another script run with no execution time restriction and call your script from it every hour.
     
    stOK, Mar 25, 2010 IP
  9. Irfi0009

    Irfi0009 Banned

    Messages:
    17,584
    Likes Received:
    33
    Best Answers:
    1
    Trophy Points:
    48
    #9
    I thing the best idea for this is to write another script with no execution time restriction and that script will then call your origenal script after every hour
     
    Irfi0009, Mar 25, 2010 IP
  10. mrdo

    mrdo Well-Known Member

    Messages:
    1,552
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    138
    #10
    If you are using a hosting with Cpanell 11, find CRON JOB and try it
     
    mrdo, Mar 25, 2010 IP
  11. viron86

    viron86 Active Member

    Messages:
    426
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #11
    cronjob in OS is Linux or schedular if OS is Windows
     
    viron86, Mar 25, 2010 IP
  12. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #12
    You can do it with PHP, it's more troubles and there are some conditions:
    * The exec() function must be available
    * You need to have a decent number of visits.

    Than you can may a scripts which do the following:
    * Check when the script was run
    * If it was run in more than one hour ago it will run it again and store the new time
    * otherwise do nothing

    Time can be stored as a timestamp on a file
     
    nabil_kadimi, Mar 25, 2010 IP
  13. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #13
    With enough traffic, you can always just set an include on every page called something like tasks.php
    and then just have a little condition that only allows the tasks to be run if the time conditions are met. Take a look at the tasks system on MyBB or similar scripts... other than that, cron is the best option
     
    Grit., Mar 25, 2010 IP
  14. adspos

    adspos Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    I think cron job is good idea, daily..., weekly, mothly...etc.
     
    adspos, Mar 25, 2010 IP
  15. ThomasTwen

    ThomasTwen Peon

    Messages:
    113
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #15
    or just google "free cronjob", and use a service to visit your script every hour.
     
    ThomasTwen, Mar 25, 2010 IP
  16. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #16
    Such as: http://www.onlinecronjobs.com/
     
    danx10, Mar 25, 2010 IP
  17. blacksheep666

    blacksheep666 Active Member

    Messages:
    68
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #17
    cron job lage... dili kasabot
     
    blacksheep666, Mar 25, 2010 IP