PHP: FIFO queue with APC

A few days ago i needed a simple queue class that would also be persistent after the pagerequest. I first thought about putting this queue in SQL but did not want the whole SQL overhead and such and remembered a blog artice about memcache queues a once read. But i had no memcache for that project and used APC instead.

Basic idea

The basic idea looks like this:
There are 2 counters, one for the current head key, and the other for the current tail key.
The main part of the code is from the mentioned blog artice, but i ported it to PHP and APC instead of Memcache.


A generated documentation can be found here:


The source can be found here:


Here is a example how to use the queue:

$q = new apc_queue('test', isset($_GET['force']));

echo "STORE: ";
for($i=0; $i<10; ++$i) {
    $rand = rand(0,9);
    echo $rand,',';
echo "\nFETCH: ";
while(($g = $q->get()) !== FALSE) {
    echo $g,',';
echo "\nLENGTH: ", $q->length();

No related posts.


Ein Kommentar zu “PHP: FIFO queue with APC”

  1. digitalpbk 29. August 2011 um 08:13

    Wish there was some locking mechanism in send and receive.