Page 1 of 1

How to create queue data structure in PHP?

Posted: Tue Nov 15, 2005 7:11 am
by ahammadi
I am doing a small experiment using Apache, MySQL and PHP on Window platform. Suppose I have following tables in MySQL: FLIGHT, CUSTOMER and FLIGHT_CONFIRMATION in Reservation database. PHP script will first check if the seat is available for a customer on the date he specified on a particular flight then the seat will be booked - that is, data will be inserted into FLIGHT_CONFIRMATION table. I want to create a queue in PHP before sending request to database server (This is requirement of my experiment). Also suppose there are many customers sending requests at the same time. Any idea that how can I create queue in PHP and store all the incoming requests before sending it to database server?
I dont want the exact code but the idea that how can we do it in PHP?
Prompt reply will be appreciated.
Thanks,
Adil

Posted: Tue Nov 15, 2005 7:24 am
by Jenk
If you will be wanting multiple concurrent users to be able to access the same queue, it will need to be a central data source, namely, another table :)

Posted: Tue Nov 15, 2005 8:23 am
by timvw
An array can be seen as a Queue:

- You can add/remove elements in the front (shift/unshift),
- and in the back (push/pop).
- You can also insert/remove at specific locations.

Anyway, if you want to avoid race conditions you should read up about "Transactions". They are a mechanism that allow you to circumvent problems that might arise.

Posted: Tue Nov 15, 2005 8:41 am
by BDKR
timvw wrote:An array can be seen as a Queue:

- You can add/remove elements in the front (shift/unshift),
- and in the back (push/pop).
- You can also insert/remove at specific locations.

Anyway, if you want to avoid race conditions you should read up about "Transactions". They are a mechanism that allow you to circumvent problems that might arise.
Exactly!