View Full Version : Concept of Holding a reservation.

05-26-2011, 05:15 PM

I was wondering how do you implement the concept of holding a registration of an event or a booking?

For instance, when you try to book a hotel room or a try to book a air ticket online, they hold your registration for say 10 or 15 mins, during which the room or seat will be locked for that time and once the time expires, they release the holding.

A real life example would be events hosting on eventbrite


How do we implement the same concept in an PHP application?

Any help will be greatful.


05-26-2011, 10:40 PM
I really don't think php can keep track of time, so if this becomes a php script you would need to start something else to do a count down for you.

To do this easier I suggest you use javascript (Ajax). I can remove or halt an html entry from being clicked on for an amount of time; it then can add the entry back onto the page if the time elapses or process the purchase all without resending the page.

05-27-2011, 03:05 AM
When the client goes to book it, put their sessionID and the time() into the database for that room. For any new clients trying to book it the script must check that the phpsession matches theirs and that the timestamp is from within the last 15 minutes.

Job done.

05-27-2011, 04:40 AM
Thanks for your reply.

I will try it and shall come back to you if I have further doubt.

THanks once again

06-11-2011, 05:33 AM
Hi Again

I have implemented the concept and it works like a charm except for one case. Our QA team has discovered an issue and I am not sure if this is the problem of the code or the database queue request.

Our QA team are testing this by clicking on the "Check Room Availability" button simultaneously on 2 different computers at a single point of time. 2 out of 20 times they succeed in breaking the rule.

For example, for 10th July 2011 only 1 room is available in a hotel. If we proceed with booking this room for the aforesaid date, the application holds the reservation for 15 mins for that user. But if the "Check Room Availability" button is clicked by 2 users at the same point of time, the rule fails 2 times out of 20 attempts.

What do you think the cause of this and how can we prevent it?

Any suggestion will be highly appreciated.

Many thanks in advance.

06-27-2012, 03:21 PM
HI Again

I have an interesting question regarding the concept of holding a reservation.

Suppose a registration is being held for a user for 20 mins, he fills up all the required forms (lets assume he spends 15 mins filling up the forms), after that the application takes him to the payment gateway page, where he spends 6-7 mins filling up teh credit card details, name etc.

In the meanwhile a CRON which is set to run every 20 mins, deletes the record of that user from the database since the user has spent more than 20 mins for completing the whole process.

After making a successful payment, when the user is redirected back to the application, the application does not find the matching record and displays an error to him saying your session has timed out etc.

How would you handle or make the application handle such a case where the user has already made the payment?

Any help / ideas will be highly appreciated.