Experts Round Table Network

Serverside Technology => PHP => Topic started by: thepreacher on June 27, 2007, 09:34:19 AM



Title: Scheduling a script run at specifictime or interval
Post by: thepreacher on June 27, 2007, 09:34:19 AM
Hi guys, i am about to write a script (like an end of day program and also one that should run every 30 mins ) that should execute periodically and do some stuff. I have never done anything like that before.

How do I get a script to do that please.

Regards all


Title: Re: Scheduling a script run at specifictime or interval
Post by: Esopo on June 27, 2007, 01:10:40 PM
Hi,

I normally use cron for that purpose:

http://www.google.com/search?q=cron+jobs

Best regards,

Esopo.


Title: Re: Scheduling a script run at specifictime or interval
Post by: VGR on June 28, 2007, 06:26:44 AM
two main solutions :
1) leave a browser window open somewhere with a refresh period
2) perform off-line calls. If you coded your PHP scripts to ba calleable with the CLI mode (see PHP.net for the CLI mode), then cron, AT, the W$ scheduler or a lot of other tools can just call the script.
2b) if you didn't adapt the script to CLI - so it works nominally only when called from a browser window in GET/POST HTTP mode - and you "accidentally" run on W$, then you're stuck. That's why I build many years ago the free tool called RobotOuaibe that you'll be able to find on www.edainworks.com, topic "tools" or "third-party" - should be easy.

I use it to launch periodic daily tasks at different times of the day (like cleaning the logs, analysing them, producing stats, calling netcraft, calling other sites for parsing their contents, etc).

For running weekly, monthly, quarterly, yearly tasks, I code the necessary tests (when was the last run? what is the date now ? should I run? etc using a DB of the filesystem) in the necessary places and the updates run automatically - and once ! ;-) - whenever the script is called, and whatever the calling mode (user, myself, or RobotOuaibe)

As those tasks are just an aggregation of statistics, it's not necessary for them to run exactly when the last period is over, as long as they run the next time the script is called.
For daily tasks that need to be called every day, I use RobotOuaibe