简体   繁体   English

x时间后增加PHP变量

[英]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. 无论用户是否在线,都将从MySQL数据库中检索它,然后将金额添加到变量中并再次发送回服务器。

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) user1是在1376936553上创建的(时间为unix时间戳记)

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 从现在开始的一个小时内,unix时间将是1376940153。如果您想找出他们应该拥有多少个可能的货币单位,将是

(currenttime - start time)/3600 = 1 (当前时间-开始时间)/ 3600 = 1

Then, if the user spends that one, keep track of it in a seperate database field and apply it to the total. 然后,如果用户花了那笔钱,请在单独的数据库字段中跟踪它,并将其应用于总数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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