what is a queue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phoggy
Forum Newbie
Posts: 20
Joined: Tue Sep 16, 2003 2:03 pm

what is a queue

Post by phoggy »

Hi,
Could someone briefly explain what a queue is and why I would use it instead of an array.
Thanks.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

Dictionary.com/queue wrote: 1. A sequence of stored data or programs awaiting processing.
2. A data structure from which the first item that can be retrieved is the one stored earliest.
So to place things in a queue instead of an array is good if you have to do something with that data that would take up a lot of server resources. To save resources, place them in a queue (in our case, a database) and then schedule, or rotate one after another between them.

The term is also used interchangeably with cache.
Dictionary.com/cache wrote:To hide or store in a cache.
A good example of using a cache is when you have to send out multiple thousand of e-mails. Instead of sending them all at the same time, you can cache 75% of the list, and then work through the list in quarters to reduce the server load.

Hope this clears things up.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You may also hear them refered to as FIFO - First In First Out. So that the first item that you place in it, will come out of it first - unlike a stack which is FILO - First In Last Out.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

The great UK past time. :D
hokiecsgrad
Forum Newbie
Posts: 17
Joined: Fri Oct 22, 2004 2:55 pm

Post by hokiecsgrad »

One of the more important distinctions between an array and a queue, which hasn't specifically been stated yet, is that an array is a random access structure while a queue (and the aforementioned stack) can only be accessed at the "top" or at the "bottom" of the structure.

Basically, queues and stacks are just special types of arrays.
Post Reply