View Full Version : Setting PHP to Timer

01-16-2008, 01:33 PM
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 :)

01-16-2008, 07:12 PM
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.

01-17-2008, 04:19 AM
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.