How to create queue data structure in PHP?

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

Post Reply
ahammadi
Forum Newbie
Posts: 1
Joined: Tue Nov 15, 2005 6:58 am

How to create queue data structure in PHP?

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 :)
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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!
Post Reply