Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing action twice - how to prevent that?

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

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 ?

like image 926
genesis Avatar asked Feb 24 '26 19:02

genesis


1 Answers

What I think is...

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.

So if you compare to $current_time, the $current_time has to be in 0000-00-00 00:00:00.00000 format too

here is the way how to get the time with miliseconds

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'

like image 106
royrui Avatar answered Feb 27 '26 10:02

royrui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!