Overbooked Booking System

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Overbooked Booking System

Postby beyondidiocy » Mon Jan 12, 2004 11:49 pm

Ok ... now let's see How could I put this so almost everybody could understand ... including myself.

Here we go .... I'm currently writing a booking module and I've been asked to make sure 1001% (this is no typo ) that no overbooking should be made. and the story goes that I've made the whole thing, until I found out that it overbooks . Now I came up with two ideas that could help.

One: Safety by numbers
In this way I could show most and not all of my products, and will help give me a cushion, range or margin (whatever its called.... I don't know).

PREOBLEM::: I don't have a large number to play with so this is scrapped ....

Two: View locking
Now this might get complicated ... Depending o the number of my products I could do something like first come first view thing. In other words I could track every single session and make sure that the number of booking don't go out of hand even if there are simultaneous (this is a typo.... I think) views of my products.

PROBLEM::: it works but is it .... lets put in one word .... GOOD or is it going to pain in the --censored--

Hope you guys can help
beyondidiocy
Forum Newbie
 
Posts: 2
Joined: Mon Jan 12, 2004 11:49 pm

Postby penguinboy » Mon Jan 12, 2004 11:53 pm

I don't really understand your problem.
What do you mean by 'booking' ?
penguinboy
Forum Contributor
 
Posts: 171
Joined: Thu Nov 07, 2002 12:25 pm

Postby beyondidiocy » Mon Jan 12, 2004 11:55 pm

OK Now ..lets see

Basic the whole thing is a hoitel reservation system that I'm building. The problem is my Boss wants me to make a 100 percent sure that it won't overbook at any time no matter what happens .... hence the whole scenario
beyondidiocy
Forum Newbie
 
Posts: 2
Joined: Mon Jan 12, 2004 11:49 pm

Postby Gen-ik » Tue Jan 13, 2004 12:55 am

One way to prevent two or more people booking the same room at the same time would be to use database locking... basically this locks the database when info is being added to it. I can't remember off-hand how this is done but checking out the [php_man]mysql[/php_man] functions in the manual might help.

Apart from that this is a simple date/time checking problem isn't it? Someone wants to book Room101 on the 10th on Jan for 2 nights so you check the database to make sure this doesn't over-run with another booking.
Gen-ik
DevNet Resident
 
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

needs an advice for php and mysql refferences book

Postby irfan » Tue Jan 13, 2004 1:36 am

i needs some advice to buy a php and mysql book which bundled in one package book.
what is the best refferences? by the way i'm the newbie in php and mysql programming.
thank you for your very kind information..

Irfan
:)
irfan
Forum Newbie
 
Posts: 1
Joined: Tue Jan 13, 2004 1:36 am

Re: needs an advice for php and mysql refferences book

Postby Gen-ik » Tue Jan 13, 2004 9:32 am

irfan wrote:i needs some advice to buy a php and mysql book which bundled in one package book.
what is the best refferences? by the way i'm the newbie in php and mysql programming.
thank you for your very kind information..

Irfan
:)


I know you are new here but you really shouldn't hijack someone elses topic like this, if you have a non-related question you should start your own topic.

In answer to your question though you will find everything you need to know about PHP and MySQL programming at http://www.php.net
Gen-ik
DevNet Resident
 
Posts: 1059
Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.

Postby /usr/local/ » Fri Mar 12, 2004 7:16 pm

beyondidiocy wrote:OK Now ..lets see

Basic the whole thing is a hoitel reservation system that I'm building. The problem is my Boss wants me to make a 100 percent sure that it won't overbook at any time no matter what happens .... hence the whole scenario



Could you please tell me if you have solved your problem. Because i am also trying to build a reservation system too. And i am a newbie :)

good luck
/usr/local/
Forum Newbie
 
Posts: 9
Joined: Fri Mar 12, 2004 7:16 pm

Postby timvw » Fri Mar 12, 2004 10:28 pm

The only problem i can come up with is when you tell each visitor how many places you have available

for example

user 1 visits -> 4 rooms available
user 2 visits -> 4 rooms available
user 2 orders 2 rooms
user 1 orders 4 rooms -> problem

To work around this:

- On every change of the reservations tables, you should also save the time of that change (update_time)

- When you query the results from the database to build up a view, also save the time (view_time)

- When there is an order generated from a view, make sure that view_time > update_time when you process the order....
timvw
DevNet Master
 
Posts: 4897
Joined: Tue Jan 20, 2004 12:11 am
Location: Leuven, Belgium

Re: Overbooked Booking System

Postby lastcraft » Sat Mar 13, 2004 12:21 pm

Hi...

I am not exactly sure what you mean by booking, so I assume it is a paid reservation:

beyondidiocy wrote:Two: View locking
Now this might get complicated ...


This is your only option. Yes it does get complicated; in fact it should have been designed in from the beginning. It is also very difficult to test, so you need to secure it by static analysis alone. Hope you have a clear head ;). Here are two approaches...

I assume that booking a room is a multipage process, so the first way is to cope with this as best we can. You cannot easily use database transactions over mutli page requests (called long transactions). It is technically difficult within PHP and is a bad idea anyway as you will bring the database server to it's knees. This means that you must implement two levels of locking.

When a buyer starts booking a room you first check that noone else is booking the room and if clear you attach the buyer to a room. The booking process cannot start without this condition. This must be transactional. For example...
Syntax: [ Download ] [ Hide ]
class Booking {

    ...

    function confirm(&$room) {

        $this->_connection->begin();

        if ($room->isBooked()) {

            $this->_connection->rollback();

            return false;

        }

        $room->book($this);

        return $this->_connection->commit();

    }

}

Now the room will be correctly held until the booking process is complete. The trouble is that if the process is abandoned the room will be locked forever. This means that you have to have a timeout within the booking object so that it can go stale after inactivity. This in turn means that each stage of the booking process must carry out a transactional check that it hasn't dropped out.

The second approach is simpler overall. That is to get the booking process onto a single page. The way to do this is for the software to do less. This may seems strange, after all we are in the business of automation, but in fact deciding what to code is a careful balancing act. By pushing the problem back out into the domain you often find that systems already exist to deal with the complexity.

I suspect that the hotel business already has rules for reservations as well as paid for bookings. They manage to cope with double bookings already right? How?. You need to ask them what their system is.

For example by splitting off reservation from paid booking you can probably get each down to a single web page. Once you do that you can use database transactions to make a room booking atomic, rather than simulating long transactions. The concept of reservation will have to be visible, as well as accompanying text explainig how it works, but the hotellier will get much more flexibility in how the system is managed. They could introduce first and second choices for example (unlikely, but you see what I mean).

Hope this helps.

Hm. I am thinking more and more these days that the concept of transactions already exists in the business world and that we as developers should make use of that knowledge...

yours, Marcus
lastcraft
Forum Commoner
 
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London


Return to PHP - Theory and Design

Who is online

Users browsing this forum: sjemgrota and 2 guests