Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


gdops

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?

PARTNERS