3 Replies - 161 Views - Last Post: 06 December 2017 - 10:12 AM Rate Topic: -----

#1 Splashsky   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 311
  • Joined: 25-August 13

Updating Database on a Timer?

Posted 06 December 2017 - 09:05 AM

So in the pursuit of making my web game, I've inevitably come to the need for timers to change user statistics on a cycle. For instance, users have a limit on how many deposits to the bank they can do per day. The current deposits they have available is stored, along with their maximum. Every 24 hours I'd like the current number to refresh to their maximum.

My original thought for timers was I could create a whole new table for timestamps related to the things that need them, then on every page refresh check those times against the current time and update the timestamps as necessary, refreshing those values as needed. I was worried about the number of queries this would take and the overhead associated with it, so I was wondering what y'alls opinion would be. :P

Is This A Good Question/Topic? 0
  • +

Replies To: Updating Database on a Timer?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14168
  • View blog
  • Posts: 56,760
  • Joined: 12-June 08

Re: Updating Database on a Timer?

Posted 06 December 2017 - 09:12 AM

That would be a fairly smart idea... of if this is a 'universal' then just bake it into the code.
Was This Post Helpful? 0
  • +
  • -

#3 Splashsky   User is offline

  • D.I.C Regular

Reputation: 11
  • View blog
  • Posts: 311
  • Joined: 25-August 13

Re: Updating Database on a Timer?

Posted 06 December 2017 - 09:21 AM

View Postmodi123_1, on 06 December 2017 - 09:12 AM, said:

That would be a fairly smart idea... of if this is a 'universal' then just bake it into the code.

The maximum can be changed per-user, so I wish I could do universal but that wouldn't work ;P

So there's no speed concerns with checking/updating like that? I doubt I'll ever reach the scale where it becomes an issue, but it was just a concern. I should be able to just create JS timers that countdown when the page loads, so that's not an issue... I did read somewhere about cron jobs; would those serve this purpose?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14168
  • View blog
  • Posts: 56,760
  • Joined: 12-June 08

Re: Updating Database on a Timer?

Posted 06 December 2017 - 10:12 AM

I guess a cron job or even just take care of it when the user logs in. Small function that checks if the current datetime is past the one in the table.. if so then update the date time, set the 'available' to what ever the max is, and off you go.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1