QUESTION
Would it work fine if I use sleep(300); to do a whole day (24 hours) in 5-minute gaps?
This means, would set_time_limit (86400); work?
Then I can set my host’s schedule to only be used once every 24 hours.
INFO
I found what I am doing now on this question and am now using it to do something every 5 minutes. It works well and is on time with even the seconds correct. (Talking about the gap between each sleep) – it sleeps 3 times and then gets called again from my host’s-schedular.
I have a scheduled task set up at my host for every 15 minutes, problem is this is not happening every (precise) 15 minutes, but more like 16 and a bit minutes – and after a few hours it is totally out of sync.
If it’s possible to use it to not quit within 24hrs, then I can adjust the sleep in the code to make it execute exactly every 5 mins.
UPDATE
17:17:50 22-09-2011 Check done!
17:34:09 22-09-2011 Check done!
17:47:47 22-09-2011 Check done!
I ran a script that appended to a file the date and “Check done!” – this was without a loop and sleep and that is what I got.
If you use
set_time_limit(0);, the code will never time out and run forever unless it exits first. For instance I write programs in PHP in awhile(1) { ... }loop. It ran for about two weeks straight (then I had to restart my computer for some unrelated reason).Cron is usually accurate though. If your host’s cron is so out of sync, you should contact them and ask about it – that’s not normal.
EDIT: Also, you might want to consider running it forever and start it manually, then having a cron task that checks if it’s still running, and restart it if it isn’t.