Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic daily script

Status
Not open for further replies.

brownfox

Programmer
Jan 5, 2003
173
GB
I have a database driven (mySQL) site running PHP. I want to implement a script that runs daily at 02.00 a.m. (for example). The script itself is quite simple - it checks to see if people have unread messages that are over 3 weeks old and, if true, puts them in a 'sin-bin',they have to read their messages before they are allowed out. What I want to know is, what's the best way to automatically run this script on a daily basis? Thanks in advance for any help on this.
 
In linux/unix you can run your script at a certain job using cron. I'm not sure of the syntax. In Windows, you can run your script by calling "php.exe" as a scheduled task (see the control panel). For instance:

Create a scheduled task to call "php.exe script.php". This will run the "script.php" at the scheduled time.

-Ron
 
I don't know what OS you are using to serve your pages, however Linux comes standard with the CRON DAEMON (cron). cron runs in the background and checks what is called the CRONTAB every minute (crontab holds the commands you wish to run, what days, and how often to run them). This means you can have a script run at 2am once a day, once every hour, noon on Thursdays, etc.

If you are running Linux (everyone should [thumbsup2]) I would suggest checking out:



If you are serving your pages from a shell account controlled by a third party service provider, then I would suggest contacting their administration or support department to see if they have cron services available for users.

If you are running on a M$ [bluegreedy] OS... then I don't know... NT probably has something like cron. I would hope it would.

If nothing else, you can always write a script to run in the background and check the time. Then execute whatever code you are in need of at the specified time.

- "Delightfully confusing..." raves The New York Times

-kas
 
Thanks for your help guys, unfortunately ensim doesn't directly support cron. At least that's what my hosting people said. So the script just gets run whenever someone hits a certain page on the site. It's not ideal but what the hey...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top