Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Member Since 23 Jul 2012
Offline Last Active Jul 23 2012 11:45 AM

Topics I've Started

Database locking/transactions techniques for browsergame PHP/MySQL

23 July 2012 - 10:56 AM

Hi everyone,

I'm wondering what's the proper way to handle concurrent actions in a browsergame, that access the same resource (e.g. one player's warehouse), combined with the "on view" method instead of cronjob.

Basically that means, instead of running some script that processes the action queues each second, the calculations are made when that resource (warehouse) is accessed the next time (e.g. one attacks and take resources, or the player itself spends some of them).

Problem obviously occurs when two players access the same resource at the same time, and I'm not sure if there's a good-proven standard way to implement this...

Some guesses of me would be:

1. Using MySQL transactions (one transactions includes: read from actions table, execute them, delete executed actions)
2. Using MySQL table lock for actions table
3. Locking with PHP flock()
4. Using semaphore with PHP sem_acquire()

Any suggestions?