Source for file class.apc_queue.php
Documentation is available at class.apc_queue.php
* @author Julius Beckmann
* @link http://juliusbeckmann.de/classes/apc_queue/
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
public function add($value);
* Simple class for fifo queues saved in APC cache
* @version v0.1_2010.01.29
* Copyright 2009 Julius Beckmann
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* Overall prefix for queue keys
* Creates queue object. Every queue needs a name.
* @param string $queue_name
* @param boolean $force_new
public function __construct($queue_name, $force_new= FALSE) {
$this->name = (string) $queue_name;
* Initializes the queue and checks for counter integrity
* @param boolean $force_new
private function init($force_new= FALSE) {
// Force new queue by resettings counters
apc_store($this->head, 0);
apc_store($this->tail, 0);
$val_head = apc_fetch($this->head, $success);
apc_store($this->head, 0);
$val_tail = apc_fetch($this->tail, $success);
apc_store($this->tail, 0);
// Check counter integrity
if($val_head < $val_tail) {
public function add($value) {
$id = apc_fetch($this->head)+ 1;
apc_store($this->head, $id);
apc_store($this->key. $id, $value);
* Fetches next value from queue. FALSE if empty.
// Reset counters if queue is empty
$id = apc_fetch($this->tail)+ 1;
apc_store($this->tail, $id);
return apc_fetch($this->key. $id);
$head = apc_fetch($this->head);
$tail = apc_fetch($this->tail);
return ($length >= 0) ? $length : 0 ;
// Check if APC has some memory left
// var_dump(apc_sma_info());
$q = new apc_queue('test', isset($_GET['force']));
echo "LENGTH: ", $q->length(), "\nSTORE: ";
echo "\nLENGTH: ", $q->length(), "\nFETCH: ";
while(($g = $q->get()) !== FALSE) {
echo "\nLENGTH: ", $q->length();
|