This is a discussion on "Every half hour script" within the PHP Forum section. This forum, and the thread "Every half hour script are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
Every half hour script
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
Every half hour script
Hi. I have a problem that I don't know how to solve.
I need a script that will run and update some info in a DB table every half an hour. The script itself shouldn't be to hard it's just I don't know how to make it run every half an hour. Is there a way to make the script run without a user being there to refresh that page? Like make the server do it or something. I really can't figure out how this will work. Thanks for your help Blake |
|
|
|
|||
|
Re: Every half hour script
Do you have either a dedicated server or VPS, or just a basic shared server?
|
|
|||
|
Re: Every half hour script
basic shared server i'm working on.
It supports cron jobs though. If it makes a difference at all. |
|
|||
|
Re: Every half hour script
All the difference as in that case it should be easy. If you have access to a personal raw crontab file, simply add a line such as:
Without cronjobs, the trick is to hook a script into a core file of your website that gets hit on every request, record when your scheduled script was last run, and if the next trigger time has passed then execute the script as part of the page request. As long as the site gets a hit at least every minute or so then you'll get a fairly or even completely accurate scheduler that way. The slightly tricky thing with this method is that it's important to avoid race conditions in some way, such as testing that the cronjob needs running, then getting a lock (e.g. a file lock with flock()), testing again, and if it still needs running then update the time that it last ran, release the lock, and then do the work. Last edited by ioncube; Aug 18th, 2007 at 00:01. |
|
|||
|
Re: Every half hour script
Thanks a lot!
I'm looking into that right now |
|
|||
|
Re: Every half hour script
You should be able to use environment variables in the crontab too, e.g.
|
![]() |
| Tags |
| half hour, no users, php |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 2 Hour Website | shawzy85 | Free Web Site Critique | 22 | Jul 9th, 2008 19:24 |
| 4 hour Website | shawzy85 | Free Web Site Critique | 8 | Apr 28th, 2008 22:03 |
| A job half done | geordief | Flash & Multimedia Forum | 12 | Sep 10th, 2007 22:32 |
| only 'half' border appears in firefox | N_K | Web Page Design | 4 | Aug 2nd, 2006 19:10 |
| Half Project | Smokie | Entry, Nominations and Voting | 0 | Aug 19th, 2003 11:58 |