<?phpclass Deque { public $queue = array(); /**(尾部)入隊(duì) **/ public function addLast($value) { return array_push($this->queue,$value); } /**(尾部)出隊(duì)**/ public function removeLast() { return array_pop($this->queue); } /**(頭部)入隊(duì)**/ public function addFirst($value) { return array_unshift($this->queue,$value); } /**(頭部)出隊(duì)**/ public function removeFirst() { return array_shift($this->queue); } /**清空隊(duì)列**/ public function makeEmpty() { unset($this->queue); } /**獲取列頭**/ public function getFirst() { return reset($this->queue); } /** 獲取列尾 **/ public function getLast() { return end($this->queue); } /** 獲取長(zhǎng)度 **/ public function getLength() { return count($this->queue); } }隊(duì)列的用途:隊(duì)列可以很好地異步處理數(shù)據(jù)傳送和存儲(chǔ),當(dāng)你頻繁地向數(shù)據(jù)庫(kù)中插入數(shù)據(jù)、頻繁地向搜索引擎提交數(shù)據(jù),就可采取隊(duì)列來(lái)異步插入。另外,還可以將較慢的處理邏輯、有并發(fā)數(shù)量限制的處理邏輯,通過(guò)消息隊(duì)列放在后臺(tái)處理,例如FLV視頻轉(zhuǎn)換、發(fā)送手機(jī)短信、發(fā)送電子郵件等。