3

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 ?

genesis
  • 50,477
  • 20
  • 96
  • 125

1 Answers1

4

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'

Community
  • 1
  • 1
royrui
  • 1,217
  • 10
  • 20
  • 1
    Thanks for it. IT might help, but there is an problem. 1. I prefer time() & unix timestamp, 2. if some attack takes more time to proccess (overloaded server, for example), proccessing can take about 1 second. and before I do change proc to 1, somebody can click. I'll try to change proc to 1 just after click (before proccessing them) – genesis Jun 04 '11 at 10:14