PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Nov 28, 2014 9:26 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Jan 12, 2004 11:49 pm 
Offline
Forum Newbie

Joined: Mon Jan 12, 2004 11:49 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 11:53 pm 
Offline
Forum Contributor

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 11:55 pm 
Offline
Forum Newbie

Joined: Mon Jan 12, 2004 11:49 pm
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 12:55 am 
Offline
DevNet Resident

Joined: Mon Aug 12, 2002 7:08 pm
Posts: 1059
Location: London. UK.
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.


Top
 Profile  
 
PostPosted: Tue Jan 13, 2004 1:36 am 
Offline
Forum Newbie

Joined: Tue Jan 13, 2004 1:36 am
Posts: 1
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
:)


Top
 Profile  
 
PostPosted: Tue Jan 13, 2004 9:32 am 
Offline
DevNet Resident

Joined: Mon Aug 12, 2002 7:08 pm
Posts: 1059
Location: London. UK.
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 7:16 pm 
Offline
Forum Newbie

Joined: Fri Mar 12, 2004 7:16 pm
Posts: 9
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 10:28 pm 
Offline
DevNet Master

Joined: Tue Jan 20, 2004 12:11 am
Posts: 4897
Location: Leuven, Belgium
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....


Top
 Profile  
 
PostPosted: Sat Mar 13, 2004 12:21 pm 
Offline
Forum Commoner

Joined: Sat Jul 12, 2003 10:31 pm
Posts: 80
Location: London
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group