noodle Posted April 6, 2007 Share Posted April 6, 2007 hello, i'm currently programming a media player very similar to Itunes for a project... i've got to the stage where i need to implement a download queue in php that allows users to download music off a website... any ideas on how to construct this?? i'm new to php so i need a bit of a kick start... i was thinking a stack? thanks Link to comment https://forums.phpfreaks.com/topic/45871-implementing-a-download-queue/ Share on other sites More sharing options...
utexas_pjm Posted April 6, 2007 Share Posted April 6, 2007 A stack is by definition, not a queue. A stack is last in first out whereas you are looking for a first in first out solution. A simple queue can be created quite easily with a simple array. Best, Patrick Link to comment https://forums.phpfreaks.com/topic/45871-implementing-a-download-queue/#findComment-222849 Share on other sites More sharing options...
utexas_pjm Posted April 6, 2007 Share Posted April 6, 2007 I whipped this up really quick, it's a VERY simple queue implementation but should be enough to get you started: <?php class Queue { var $queue; var $index; var $size; function Queue() { $this->queue = array(); $this->index = 0; $this->size = 0; } function enqueue($obj) { ++$this->size; $this->queue[] = $obj; } function dequeue() { if($this->size <= $this->index){ $this->_handleError("Queue is empty"); } $ret = $this->queue[$this->index]; ++$this->index; return $ret; } function isEmpty() { return ($this->size <= $this->index); } function _handleError($msg) { echo 'Error: ' . $msg; } } $q = new Queue(); $q->enqueue("foo"); $q->enqueue("bar"); while(!$q->isEmpty()){ echo $q->dequeue() . " "; } ?> Best, Patrick Link to comment https://forums.phpfreaks.com/topic/45871-implementing-a-download-queue/#findComment-222854 Share on other sites More sharing options...
noodle Posted April 6, 2007 Author Share Posted April 6, 2007 thanks a lot i don't have a computer at the moment but will give a try tomorrow and let u know what happens Link to comment https://forums.phpfreaks.com/topic/45871-implementing-a-download-queue/#findComment-222895 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.