简体   繁体   中英

Increment PHP variable after x time

I want to make a site with an online currency that increments every hour, or any other time frame. It's going to be retrieved from a MySQL database, no matter if the user is online or not, and then an amount is going to be added to the variable and sent back to the server again.

I've looked around but still struggling to get my head around the explanations.

Any help is greatly appreciated.

Thanks in advance!

To reduce constant database updates for a large number of users, you could keep track of the user's creation time and calculate the amount of currency they should have from there. You would also probably have to have a modifier for any additional spent/stolen/earned money.

example:

user1 was created on 1376936553 (the time as a unix timestamp)

an hour from now, the unix time will be 1376940153. If you want to find out how many possible units of currency they should have it would be

(currenttime - start time)/3600 = 1

Then, if the user spends that one, keep track of it in a seperate database field and apply it to the total.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM