Jump to content

implementing a download queue


noodle

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.