php - adding numbers to a database over time.

Associate
Joined
11 Oct 2008
Posts
268
Hi guys. I'm trying to think of a way to increase the number in a database over time. Its for a resourse section for a game im creating. Similar to lords and knights if anyone has played that on their phones.

At the moment the game refreshes every 30 seconds so I can easily code it to add +1 to the database on every refresh.

But I have no idea how I would make it so the +1 was added say every minute, even when the user was logged out.

I was wondering if someone could suggest some reading material or some function to look up that may help me with this.

I have tried google but not had much luck.

Thanks for any help
 
Associate
OP
Joined
11 Oct 2008
Posts
268
Thanks. I have done a quick google on cron jobs. So If Im understanding it correctly, I would have a simple bit of code to add+1 to the database, then I would set up a cron job in my hosting control panel to execute the code every minute. Is that correct ?
 
Associate
Joined
16 Jan 2008
Posts
2,350
As billysielu is suggesting, just calculate the time between the last time you added 1 to the database and just add the appropriate amount of 1s. So all you'd need to do is add a timestamp to when a 1 is added.
 
Soldato
Joined
19 Feb 2010
Posts
13,254
Location
London
I do something similar with increments on one of my tools and as mentioned above, I just use epoch timestamps each time the DB is updated, so I can do easy subtraction to find out how long ago the last update was. Much more reliable than a cron job (which tends to stop running when someone else messes up the crontab).
 
Back
Top Bottom