PHPackages                             unionofrad/li3\_queue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. unionofrad/li3\_queue

ActiveLithium-library[Queues &amp; Workers](/categories/queues)

unionofrad/li3\_queue
=====================

This plugin provides a simple way to handle work queues.

1215110PHP

Since Jul 3Pushed 8y ago5 watchersCompare

[ Source](https://github.com/UnionOfRAD/li3_queue)[ Packagist](https://packagist.org/packages/unionofrad/li3_queue)[ RSS](/packages/unionofrad-li3-queue/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Lithium Queue Plugin
====================

[](#lithium-queue-plugin)

by `Christopher Garvis` &amp; `Olivier Louvignes`

### Description

[](#description)

This plugin provides a simple way to handle work queues, it currently supports:

- [AMQP](http://pecl.php.net/package/amqp/)
- [Beanstalk](http://kr.github.com/beanstalkd/)
- [Gearman](http://gearman.org/) in the gearman branch

### Installation

[](#installation)

1. To enable the library add the following line at the end of `app/config/bootstrap/libraries.php`:

    ```
    Libraries::add('li3_queue');
    ```
2. Then configure your queues in `app/config/bootstrap/queues.php`:

    ```
    use li3_queue\storage\Queue;

    Queue::config(array('default' => array(
        'adapter' => 'Beanstalk',
        'host' => '127.0.0.1',
        'port' => 11300
    )));
    ```
3. Update `app/config/bootstrap.php` to include this new configuration file:

    ```
    /**
     * Include this file if your application uses one or more queues.
     */
    require __DIR__ . '/bootstrap/queues.php';
    ```
4. You can now use your configured queues in your application:

    ```
    use li3_queue\storage\Queue;
    ```
5. There is some [known bugs](https://bugs.php.net/60817) with several PHP versions regarding the `stream_get_line` function that can incorrectly fail to return on `\r\n EOL` packets. Unfortunately this bug affects the 12.04 shipped PHP version (php5.3.10-1).

#### Settings

[](#settings)

1. If `autoConfirm` is true messages will be automatically confirmed on the server and whenever you use `Queue::read()` or `Queue::consume()`. This means you will not need to use `$message->confirm()` and will be unable to requeue using `$message->requeue()`.

### AMQP interface

[](#amqp-interface)

#### Configuration

[](#configuration)

Configuration for your queue will go in `app/config/bootstrap/queues.php` and can contain any of the following options:

##### 1. Basic

[](#1-basic)

```
Queue::config(array(
    'default' => array(
        'adapter' => 'AMQP',
        'host' => '127.0.0.1',
        'login' => 'guest',
        'password' => 'guest',
        'port' => 5672,
        'vhost' => '/',
        'exchange' => 'li3.default',
        'queue' => 'li3.default',
        'routingKey' => null,
        'autoConfirm' => false,
        'cacert' => null,
        'cert' => null,
        'key' => null,
        'verify' => true
    )
));
```

##### 2. Publish/Subscribe

[](#2-publishsubscribe)

To configure the AMQP adapter to function as publish/subscribe, you can create multiple queue configs in the following way:

```
Queue::config(array(
    'publish' => array(
        'adapter' => 'AMQP',
        'exchangeType' => AMQP_EX_TYPE_FANOUT,
        'exchange' => 'li3.publish',
        'queue' => false,
    ),
    'subscribe.1' => array(
        'adapter' => 'AMQP',
        'exchangeType' => AMQP_EX_TYPE_FANOUT,
        'exchange' => 'li3.publish',
        'queue' => 'li3.subscribe.1'
    ),
    'subscribe.2' => array(
        'adapter' => 'AMQP',
        'exchangeType' => AMQP_EX_TYPE_FANOUT,
        'exchange' => 'li3.publish',
        'queue' => 'li3.subscribe.2'
    )
));
```

Additional notes:

1. `routingKey` when `null` will be set by default to the same value as `queue`, setting the routing key will only be needed in advanced configurations

### Beanstalk interface

[](#beanstalk-interface)

#### Configuration

[](#configuration-1)

Configuration for your queue will go in `app/config/bootstrap/queues.php` and can contain any of the following options:

```
Queue::config(array(
    'default' => array(
        'adapter' => 'Beanstalk',
        'host' => '127.0.0.1',
        'port' => 11300,
        'tube' => 'default',
        'autoConfirm' => false
    )
));
```

- Check [source](https://github.com/UnionOfRAD/li3_queue/blob/master/extensions/adapter/queue/Beanstalk.php) for additional configuration.

### Usage

[](#usage)

1. Write a message

    ```
    Queue::write('default', 'message');
    ```
2. Read a message

    ```
    $message = Queue::read('default');
    ```
3. Confirm or requeue a message

    Once you've read a message from the queue you will either need to confirm it's success using:

    ```
    $message->confirm();
    ```

    Or requeue your message using:

    ```
    $message->requeue();
    ```
4. Consume messages

    ```
    Queue::consume('default', function($message) {
        // Do something with message
        if($success) {
            // Confirm message
            $message->confirm();
        }
        // Requeue message
        $message->requeue();
    });
    ```

    Consuming messages is a blocking action which will retrieve the next available message and pass it off to the callback. Returning false in the callback will break out of the consume.

### Bugs &amp; Contribution

[](#bugs--contribution)

Patches welcome! Send a pull request.

Post issues on [Github](https://github.com/UnionOfRAD/li3_queue/issues)

### License

[](#license)

```
Copyright (c) 2012, Union of RAD http://union-of-rad.org
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
        this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
        this list of conditions and the following disclaimer in the documentation
        and/or other materials provided with the distribution.
    * Neither the name of Lithium, Union of Rad, nor the names of its contributors
        may be used to endorse or promote products derived from this software
        without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/99c2535a12c2ded498726479567d621eaf6bddbac39419c2683a15349e597e3e?d=identicon)[notomato](/maintainers/notomato)

---

Top Contributors

[![cgarvis](https://avatars.githubusercontent.com/u/213125?v=4)](https://github.com/cgarvis "cgarvis (12 commits)")[![mgcrea](https://avatars.githubusercontent.com/u/108273?v=4)](https://github.com/mgcrea "mgcrea (11 commits)")[![markwilde](https://avatars.githubusercontent.com/u/1133385?v=4)](https://github.com/markwilde "markwilde (6 commits)")[![agborkowski](https://avatars.githubusercontent.com/u/170557?v=4)](https://github.com/agborkowski "agborkowski (3 commits)")[![jasonroyle](https://avatars.githubusercontent.com/u/439662?v=4)](https://github.com/jasonroyle "jasonroyle (2 commits)")

---

Tags

plugin

### Embed Badge

![Health badge](/badges/unionofrad-li3-queue/health.svg)

```
[![Health](https://phpackages.com/badges/unionofrad-li3-queue/health.svg)](https://phpackages.com/packages/unionofrad-li3-queue)
```

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[amphp/parser

A generator parser to make streaming parsers simple.

14952.8M16](/packages/amphp-parser)[amphp/serialization

Serialization tools for IPC and data storage in PHP.

13451.1M18](/packages/amphp-serialization)[enqueue/enqueue

Message Queue Library

19820.0M56](/packages/enqueue-enqueue)[deliciousbrains/wp-background-processing

WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.

1.1k409.8k6](/packages/deliciousbrains-wp-background-processing)[react/async

Async utilities and fibers for ReactPHP

2238.8M171](/packages/react-async)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
