最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Online Hotel Booking System, Simultaneous Booking? - Stack Overflow

programmeradmin2浏览0评论

I'm asked to create an online booking system with online payment and I'm wondering what to do in the case when 2 customers booked for the same room(s) at the same time.

For Example:
At the same time:

Customer1 and Customer2 booked for a standard room which only has 1 room available. (The Room availability will display that there is still 1 room available). And then they hit the 'confirm' button at the same time.

I'm asked to create an online booking system with online payment and I'm wondering what to do in the case when 2 customers booked for the same room(s) at the same time.

For Example:
At the same time:

Customer1 and Customer2 booked for a standard room which only has 1 room available. (The Room availability will display that there is still 1 room available). And then they hit the 'confirm' button at the same time.

Share Improve this question edited Nov 25, 2011 at 1:40 Trott 70.2k27 gold badges182 silver badges217 bronze badges asked Nov 25, 2011 at 1:36 KiiroSora09KiiroSora09 2,28718 silver badges22 bronze badges 9
  • Why the downvotes? I think this is a valid question. – Matti Virkkunen Commented Nov 25, 2011 at 1:47
  • Put a warning at the bottom of your screen that reservations are not final until confirmed, and then give an error message to whichever user was slightly too slow - they're not really hitting "confirm" at exactly the same time, so one or other request will get in first and update your database while the other request should result in an appropriate error message. – nnnnnn Commented Nov 25, 2011 at 1:51
  • 2 @nnnnnn: ...until the unexpected happens and two requests do run simultaneously (in two separate threads). Something like this requires a lock or transaction to be realiable. – Matti Virkkunen Commented Nov 25, 2011 at 1:53
  • P.S. You can introduce a temporary-hold system to give the user ten minutes to confirm after a room is first selected so that they don't go to the trouble of entering all their details before being told they've missed out, but the same principle applies that somebody is going to get in first and the next person should get a (friendly) error message. – nnnnnn Commented Nov 25, 2011 at 1:54
  • @Matti - sorry, I intended to imply that the database update would be the concurrency-control mechanism, assuming that the underlying database won't allow two threads to update the same record simultaneously even if the http requests are processed simultaneously. – nnnnnn Commented Nov 25, 2011 at 1:56
 |  Show 4 more ments

3 Answers 3

Reset to default 6

Use a locking construct (probably on the database level in this case) to ensure that only one confirmation will go through at once. You should always do this if it's possible to have a race condition like this. That way you will always know who was first, and you can tell the other user that they were too slow to confirm.

Another thing you might want to add is a payment time limit. In many systems, when you confirm something, you will have a certain amount of time to make a payment to get the reservation. If you don't pay within that time, the confirmation will expire and the room will once again be available.

There's a couple of ways to bat this.

  1. If I user selects a room, temporarily remove it as available from your web front-end. Then any subsequent visitors will not be able to select that room for booking. If the first user doesn't plete the transaction, then the room bees available again.
  2. Put a lock on the database as mentioned above so only one record can be written at any time

Use a "provisional" system that marks the booking as provisional for, say 10 minutes. These slots then bee unavailable to subsequent requests. If the booking is not pleted within the time frame the slot is released again. If you grab all the customer detail before they book the slot then the drop-out rate should stay low.

You must municate the time-frame and it's "provisional status" to the booker. If you have subsequent stages where the visitor could stop then a simple JS timer counting down the time would help and also push the booker along the process.

Alternatively, allow double booking until such time as the final "pay" button is pressed when it bees first es first. The second method would convert better, the first method is more "correct".

发布评论

评论列表(0)

  1. 暂无评论