问题描述
我有一个问题。
我有我自己的浏览器游戏,并有像
I've got a problem.I have my own browser game, and there is something like
SELECT * FROM attack WHERE proc = 0 AND endtime < $current_time
它可以工作,但问题是,当有超过10个用户在线时, 2个用户同时点击=攻击是处理两次的机会。但是,我不想增加查询计数有列例如锁定。有人知道解决方案吗?
it works, but problem is that when there are more than 10 users online, there is big chance that 2 users click at same time = attack is proccessing twice. However, I do not want to increase query count to have "column" for example "locked". Does anybody know solution ?
推荐答案
我认为...
而不是只存储0000-00-00 00:00:00,我想你可以存储在更精确的datetime,如0000-00-00 00:00:00.00000(毫秒)。
Instead of just storing 0000-00-00 00:00:00, i think you can store-in more precisely datetime, like 0000-00-00 00:00:00.00000 (miliseconds). The chances of concurrent action will decrease much.
所以如果你比较$ current_time,$ current_time必须是0000-00-00 00:00:00.00000格式
So if you compare to $current_time, the $current_time has to be in 0000-00-00 00:00:00.00000 format too
注意:您可以将日期(Ymd\TH:i:s)更改为日期(Ymd H :i:s),如果你不想要'T'
Note: you can change date("Y-m-d\TH:i:s") to date("Y-m-d H:i:s") if you don't want the 'T'
这篇关于处理动作两次 - 如何防止?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!