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()
gdopsMember Since 23 Jul 2012
Offline Last Active Jul 23 2012 11:45 AM