/    Sign up×
Community /Pin to ProfileBookmark

How to build a database updater?

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?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@pyroDec 10.2004 — [i]Originally posted by BuezaWebDev [/i]

[B](something that relates to a cronjob, but isn't a cronjob)[/B][/QUOTE]
Why not a cronjob?
Copy linkTweet thisAlerts:
@NogDogDec 10.2004 — Something like this?
[code=php]
<?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);
}
?>
[/code]
Copy linkTweet thisAlerts:
@pyroDec 10.2004 — What happens when your PHP script times out? Also, for obvious reasons, I wouldn't recommend doing it that way at all...
Copy linkTweet thisAlerts:
@NogDogDec 10.2004 — [i]Originally posted by pyro [/i]

[B]What happens when your PHP script times out? Also, for obvious reasons, I wouldn't recommend doing it that way at all... [/B][/QUOTE]

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.... ?
Copy linkTweet thisAlerts:
@BuezaWebDevauthorDec 10.2004 — [i]Originally posted by NogDog [/i]

[B]Something like this?

[code=php]
<?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);
}
?>
[/code]
[/B][/QUOTE]


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).
×

Success!

Help @BuezaWebDev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...