1

I am new to web development and I've decided to implement concurrency in a Cinema ticketing website. So for example, when a customer selects a seat, I would like to lock the seat temporarily, rather than get interference from other customer, or avoid the scenario where two customers select the seat at the same time.

The scripting language and database I have chosen to develop this website are PHP, Javascript and MySQL.

Please give some suggestions or links about what technique I should use to fix it? Is that considered concurrency?

Marvin Pinto
  • 30,138
  • 7
  • 37
  • 54
NaiveBz
  • 834
  • 2
  • 8
  • 19
  • Ensure that your database engine of choice in MySQL supports transactions, and look at using MySQL EVENTS to release seat locks – Mark Baker Jan 26 '12 at 11:55

1 Answers1

1

This answer suggests a good way of doing this:

[...] create a column containting a timestamp. Whenever you want to lock the row you update it to the current time. To unlock update to a time at least x minutes in the past. Then to check if its locked check that the time stamp is at least x minutes old.

This way if the process crashes (or the user never completes their operation) the lock effectively expires after x minutes.

Community
  • 1
  • 1
Samuel Harmer
  • 4,264
  • 5
  • 33
  • 67