How I run or execute a php file regularly without using cron jobs ?

Discussion in 'Site & Server Administration' started by energetic, Dec 4, 2007.

Thread Status:
Not open for further replies.
  1. #1
    energetic, Dec 4, 2007 IP
  2. ismu

    ismu Peon

    Messages:
    247
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I believe cron is the best solution you can use ... other than manually open the web everyday by yourself ;)
     
    ismu, Dec 6, 2007 IP
  3. jon0704

    jon0704 Peon

    Messages:
    606
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    lol, that would be fun :) specially if you need to perform the task every 6 hours :)
     
    jon0704, Dec 6, 2007 IP
  4. powerspike

    powerspike Peon

    Messages:
    312
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    what you can do, is in your script, have it exucute randomly on page load - say, get your page to generate a random number like 1-10, and if it's say 5, run the script, if you know how to use a database, get it run everytime, but only do the required work it it hasn't run in XXX minutes/hours.

    that is how vb does it, if you check they have cron.php called from every page.
     
    powerspike, Dec 6, 2007 IP
  5. jexxie

    jexxie Peon

    Messages:
    71
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Do you not have access to cronjobs? I would recommend getting access to them, they're the best solution for this.
     
    jexxie, Dec 7, 2007 IP
  6. hostingonweb

    hostingonweb Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The only option that I would say is set a cron for every day. Or do it manually every day.
     
    hostingonweb, Dec 7, 2007 IP
  7. litebulb1

    litebulb1 Peon

    Messages:
    151
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #7
    litebulb1, Dec 7, 2007 IP
  8. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Because cron is the tool designed specifically to do the job you are asking for, anything else is going to involve some sort of compromise.

    You could run a command like this on the server:
    while true; do cron_script.php && sleep 21600; done
    Code (markup):
    This infinite loop will run your script and then sleep for 21600 seconds (6 hours).

    The compromise is that it will get a second or two later every time it is run because the 21600 seconds don't start until after the script is finished. You will probably also need to run it in a screen session so that it isn't killed when you disconnect.

    Running a cron job on your home computer that calls a page on your webserver has the disadvantage of not working when you aren't connected. Webcron.org has the same problem but presumably with much greater reliability. Both of these methods have the disadvantage of running as the Apache user which may not have the correct permssions to do what you want to do.

    Testing the time the cron-like command was last run in every PHP page on your website has both of the disadvantages mentioned above: it runs as the Apache user and it relies on user-generated traffic which may not arrive at the time you need it to arrive.

    Of course, if these compromises are acceptable to you then you can choose to go with any one of them.
     
    Ladadadada, Dec 8, 2007 IP
  9. energetic

    energetic Well-Known Member

    Messages:
    2,844
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #9
    thanks.
    If I set this cron in control panel, what is the url I enter ?

    [​IMG]
     
    energetic, Feb 7, 2008 IP
  10. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #10
    That's not a URL, that's a server path to the script you want to run. Because it's a shell script, if it's written in PHP then the first line will need to be:
    #!/usr/bin/php
    Code (markup):
    and you will have to make sure that it is executable by running chmod +x /home/forums/my_cron_job.php.

    Also, if you are intending on keeping the location of your website off this discussion then you might want to remove the IP address from the bottom of that screenshot...
     
    Ladadadada, Feb 10, 2008 IP
Thread Status:
Not open for further replies.