views:

42

answers:

2

I'm developing a web application with zend framework. It is an app for selling movie tickets. The app allows users to select a seat and then buy the ticket. (The problem is similar to the classical air ticket booking.) I have two problems.

Problem 1: The page that shows all seats has to refresh with ajax (a seat is green if available and red if unavailable): each seat is a div in the page. For example if USER A is watching the page with the seats and another USER B buy a ticket, the corresponding seat has to become red for USER A without refresh the page. How could i refresh every div? i'd like to use jquery, i tried to do a json request for each div every second but it is too slow. Any idea?

Problem 2: How could i manage the concurrency? If USER A and USER B click simultaneously to buy the same ticket (a ticket for the same seat) what do i have to do? I'm using a InnoDB engine, but do i have to manage the transaction in the relative controller?

Thanks a lot!

A: 

I think that you could use Comet for problem 1 to push the data from your webserver to the browser.

Unfortunately, I don't know how to use this practically.

Natrium
A: 

I would probably solve problem 1 and 2 differently (as I have seen on lots of ticketing sites). Once a user selects a seat, I would update the seat with a timestamp in the database. That would infer that the seat is taken. The user then has 1 minute (or some amount of time) to purchase the tickets. If they don't then the timestamp changes back to null.

The sql would be fairly easy. Basically the system would scan that table for person B and say return any available seats (rows in the database) where the timestamp is null or (now - timestamp > 1 minute).

Arthur Frankel