Click to See Complete Forum and Search --> : How to build a database updater?
BuezaWebDev
12-10-2004, 01:02 AM
I was wondering how would someone go about coding a ticker program that can (at every hour of xx:00:00), update a table of the database based on a certain row?
Okay, lemme change the question. How do you build a program that can run on the background (something that relates to a cronjob, but isn't a cronjob) to update rows every hour?
Originally posted by BuezaWebDev
(something that relates to a cronjob, but isn't a cronjob)Why not a cronjob?
NogDog
12-10-2004, 08:53 AM
Something like this?
<?php
$intervalMinutes = 60; # how often to do it in minutes
$precisionSeconds = 60; # how precisely to check if it's time for next one
$lastRun = time() - ($intervalMinutes * 60);
while(TRUE) # <<<--- warning: infinite loop
{
if(time() >= $lastRun + ($intervalMinutes * 60) )
{
$lastRun = time();
#
# do your database stuff here
#
}
sleep($precisionSeconds);
}
?>
What happens when your PHP script times out? Also, for obvious reasons, I wouldn't recommend doing it that way at all...
NogDog
12-10-2004, 09:07 AM
Originally posted by pyro
What happens when your PHP script times out? Also, for obvious reasons, I wouldn't recommend doing it that way at all...
I was assuming it would be run as a command line program, not as a web page request. But we all know what happens when you assume.... :)
BuezaWebDev
12-10-2004, 03:31 PM
Originally posted by NogDog
Something like this?
<?php
$intervalMinutes = 60; # how often to do it in minutes
$precisionSeconds = 60; # how precisely to check if it's time for next one
$lastRun = time() - ($intervalMinutes * 60);
while(TRUE) # <<<--- warning: infinite loop
{
if(time() >= $lastRun + ($intervalMinutes * 60) )
{
$lastRun = time();
#
# do your database stuff here
#
}
sleep($precisionSeconds);
}
?>
Wow, that makes total sense! Thanks for the help! so, with the sleep function, it'll delay the tick for an hour and then on that hour, it'll update the rows? That's awesome.
Thanks guys, I also have a question--how would I use this ticker in a command line instead of a script?? I want to be able to go into my admin and click Ticker Activated(continue game) or Ticker De-activated (pause game).