Results 1 to 3 of 3

Thread: Setting PHP to Timer

  1. #1
    Join Date
    Aug 2007
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Setting PHP to Timer

    Hello again, I have a bit of a random query. I have a website that requires info to be refreshed and updated (price, in stock/out of stock) etc. I have a successful script that allows me to do this but it means having to automatically run it every morning when i get up and hence miss some opportunities as i can forget until mid-day etc.

    is there a way of setting a timer to a script so that eg. www.dogfightuk.com/update.php will run every morning at say 6am or would I implement something within the script of update.php.

    Help required. Many thanks

  2. #2
    Join Date
    Jan 2007
    Posts
    629
    Thanks
    10
    Thanked 28 Times in 28 Posts

    Default

    As far as I know, PHP does not have that capability. However, you can put a javascript on a page which will automatically refresh every day. As long as you keep that page open, it will work. Simple, but not the best solution.

    The alternative is to update the information when someone logs onto the site (which I think is a better way to go). One way to do so is to update every time the site is accessed. The other way is to keep a text file on the server which contains the time of the last update. When a user accesses the site, your script can check and, if it needs to update again, it will update the information and update the file storing the last update time.

    I don't know if that made sense, but. . . Hope it helps you a bit.
    --Jas
    function GreatMinds(){ return "Think Like Jas"; }
    I'm gone for a while, but in the meantime: Try using my FTP script | Fight Bot Form Submissions

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    This is not possible using PHP alone.

    However, there are two ways this can be done:

    1. Using Javascript (or another self-refreshing option) you can run this repeatedly, but that requires having it open on a computer. If you have physical access to the server, you could run the page there and just keep it in a loop.

    2. The better way would be setting up a Cron Job, which is a time based auto-run setting on your server. The server would need this capability, though. Then it's just a matter of adding the page and how often, and that's it.


    Note, also, that you could include this in your index page and just hope people access the index enough. You could also store a check to see if it's been run that day-- if not, run it, if so, skip. Also, if it runs, store that it's been checked. Done.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •