PHPackages                             zwilias/beanie - 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. zwilias/beanie

ActiveLibrary[Queues &amp; Workers](/categories/queues)

zwilias/beanie
==============

A clean, lean PHP beanstalkd client library

0.1.2(10y ago)171351MITPHPPHP &gt;=5.5.0

Since Jul 26Pushed 9y ago3 watchersCompare

[ Source](https://github.com/zwilias/beanie)[ Packagist](https://packagist.org/packages/zwilias/beanie)[ Docs](https://github.com/zwilias/beanie)[ RSS](/packages/zwilias-beanie/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (1)

Beanie
======

[](#beanie)

> A clean, lean PHP beanstalkd client library

[![Build Status](https://camo.githubusercontent.com/f8839a0b0e39527d34cae4eb08aaa02b61d4e6bf5ed4da54802bdc89d919069f/68747470733a2f2f7472617669732d63692e6f72672f7a77696c6961732f6265616e69652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zwilias/beanie)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2ad8897a04e827ac78296dd71a43a773f8394574ecfa0a441332c3ab281dc3c0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a77696c6961732f6265616e69652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zwilias/beanie/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/75843ec1f795a1d44b20f8c3644691f866b8336630e8783d041c6dd876f7917d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7a77696c6961732f6265616e69652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/zwilias/beanie/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/2ebb0903cacc3337be7e1ae0de076f2186a5272f397b9f61612023958de4acf3/68747470733a2f2f706f7365722e707567782e6f72672f7a77696c6961732f6265616e69652f762f737461626c65)](https://packagist.org/packages/zwilias/beanie)[![Total Downloads](https://camo.githubusercontent.com/2e3915cadb71c2340a87180c310e0191c5aff667681c42a081c656eb4019887e/68747470733a2f2f706f7365722e707567782e6f72672f7a77696c6961732f6265616e69652f646f776e6c6f616473)](https://packagist.org/packages/zwilias/beanie)[![SensioLabsInsight](https://camo.githubusercontent.com/305218e3d273ae074e4cb771ed5a3dd4502caf20163cc99744e408bd2e8dc40c/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66643566373735392d323463372d343832622d613037372d3335363365363563386164642f6d696e692e706e67)](https://insight.sensiolabs.com/projects/fd5f7759-24c7-482b-a077-3563e65c8add)

Core features
-------------

[](#core-features)

- Support for connection pools
- Clean distinction between concerns: Producers, Workers and Managers
- Clean interface. Want to touch a Job? `$job->touch();`
- Full support for the beanstalk protocol [as documented](https://github.com/kr/beanstalkd/blob/master/doc/protocol.md) at the time of writing

Quickstart
----------

[](#quickstart)

Requirements:

- PHP 5.5, 5.6 or 7.x
- beanstalkd 1.3 or higher
- PHP `socket_*` functions must not be disabled

### Producer

[](#producer)

A *Producer* exposes the necessary commands to produce jobs on the queue. It operates on an entire *Pool*, and will create its jobs on random connections from that pool, as a means of randomly distributing load to the workers.

```
use Beanie\Beanie;

// create a Producer for the pool
$producer = Beanie::pool(['localhost:11300', 'otherhost:11301'])->producer();

// tell the producer all jobs created should go to a certain tube
$producer->useTube('some-tube');

// put the job on a random connection in the pool
$job = $producer->put('some job data');
print_r($job->stats());
```

### Worker

[](#worker)

A *Worker* exposes the commands needed to consume jobs from the queue. Rather than operating on the entire *Pool* - like the *Producers* do - it only operates on a single connection. The idea behind this is to ensure, on an architectural level, that each beanstalk queue requires as least on Worker to operate, and you won't have one queue filling up because all your workers are waiting for a job from a different queue.

```
use Beanie\Beanie;

// get a Worker for a named connection in the pool
$worker = Beanie::pool(['localhost:11300', 'otherhost:11301'])->worker('otherhost:11301');

// tell the Worker to add a tube to the watchlist
$worker->watch('some-tube');

// now let's get ourselves some work to do
$job = $worker->reserve();

// get the data…
echo $job->getData();

// … and delete the job
$job->delete();
```

### Manager

[](#manager)

The *Managers* do exactly what it says on the package. They're your go-to class for writing code to get a view on how your beanstalk instances are performing, or occasionally kicking buried jobs on to the queue again. They expose statistics on every connection and every tube on every connection.

```
use Beanie\Beanie;
use Beanie\Tube\Tube;

// get a Manager instance for each connection in the pool
$managers = Beanie::pool(['localhost:11300', 'otherhost:11301'])->managers();

// print stats for each connection in the pool
foreach ($managers as $manager) {
    print_r($manager->stats());
}

// print stats for each tube of the first connection in the pool
$manager = reset($managers);

array_map(
    function (Tube $tube) {
        print_r($tube->stats());
    },
    $manager->tubes();
);
```

Installation
------------

[](#installation)

Installation is recommended to happen through [composer](https://getcomposer.org/).

```
# Install composer
$ curl -sS https://getcomposer.org/installer | php

# Require Beanie
$ php composer.phar require zwilias/beanie

# Check your vendor/ directory!

```

Architecture
------------

[](#architecture)

### Use case

[](#use-case)

Each producer writes to random connections on the pool. Each worker handles a single connection -- which doesn't preclude the possibility of having multiple workers for each queue, of course.

This is a PHP library, and as such, is optimized for the most common use case - short lived producers which create jobs during page generation and offload them to longer lived workers.

[![HTML View on Gliffy](https://camo.githubusercontent.com/4e17c8ea34de0acbff8f9014c6aad15bc54fbe95b75fe5fd322994b1377152a0/687474703a2f2f7777772e676c696666792e636f6d2f676f2f7075626c6973682f696d6167652f383630303834312f4c2e706e67)](http://www.gliffy.com/go/publish/8600841)

**However**: using the `Worker::reserveOath` method which returns a `JobOath` object, one could poll multiple workers for a Job. The reserveOath method writes the blocking reserve command to the beanstalk connection, but does not enter the blocking read call until the `invoke` method is called on the returned `JobOath` object. The `JobOath` object also exposes the raw socket resource, so using `socket_select` or something like and `\EvIo` watcher could enable a use-case like so:

[![HTML View on Gliffy](https://camo.githubusercontent.com/01a6d6fdfe5f605fe5896ca124e5a9c0dad8c35abfc84da79bbddb9ce73df2a2/687474703a2f2f7777772e676c696666792e636f6d2f676f2f7075626c6973682f696d6167652f383633303236312f4c2e706e67)](http://www.gliffy.com/go/publish/8630261)

The above use case is implemented in [QMan](https://github.com/zwilias/qman), check it out!

### Class map

[](#class-map)

Classes a "casual" user would come into contact with are highlighted in green.

[![HTML View on Gliffy](https://camo.githubusercontent.com/bb9ade166905857d6c083223e840e1cd6d23987dd4bad6b05e7744752ae06cd2/687474703a2f2f7777772e676c696666792e636f6d2f676f2f7075626c6973682f696d6167652f383535393436372f4c2e706e67)](https://www.gliffy.com/go/publish/8559467)

Contributing
------------

[](#contributing)

Pull requests are appreciated. Make sure code-quality (according to [scrutinizer](https://scrutinizer-ci.com/)) doesn't suffer too badly. Make sure you add thorough white-box unit tests and, if applicable, black-box integration tests.

Running the tests locally:

```
$ git clone https://github.com/zwilias/beanie.git
$ cd Beanie
$ composer install
$ vendor/bin/phpunit

```

**Note**: Some of the integration tests depend on a locally running beanstalkd. These tests are excluded in the default phpunit.xml.dist file. In order to include them, run phpunit with the `--group __nogroup__,beanstalk` flag. If you want the tests to connect to a server other than `localhost:11300`, set the `BEANSTALK_HOST` and `BEANSTALK_PORT` environment variables.

License
-------

[](#license)

Copyright (c) 2015 Ilias Van Peer

Released under the MIT License, see the enclosed `LICENSE` file.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~35 days

Recently: every ~43 days

Total

6

Last Release

3773d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8261843cef72448e4ebfb83b88355888d332b84e7143ed0f3d5eccf77d108fdb?d=identicon)[zwilias](/maintainers/zwilias)

---

Top Contributors

[![zwilias](https://avatars.githubusercontent.com/u/1038427?v=4)](https://github.com/zwilias "zwilias (2 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

queuebeanstalkdworker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zwilias-beanie/health.svg)

```
[![Health](https://phpackages.com/badges/zwilias-beanie/health.svg)](https://phpackages.com/packages/zwilias-beanie)
```

###  Alternatives

[swarrot/swarrot

A simple lib to consume RabbitMQ queues

3654.4M8](/packages/swarrot-swarrot)[foxxmd/laravel-elasticbeanstalk-queue-worker

Deploy your Laravel application as a queue worker on AWS ElasticBeanstalk

5493.5k](/packages/foxxmd-laravel-elasticbeanstalk-queue-worker)[clue/mq-react

Mini Queue, the lightweight in-memory message queue to concurrently do many (but not too many) things at once, built on top of ReactPHP

144691.7k4](/packages/clue-mq-react)[davidpersson/beanstalk

Minimalistic PHP client for beanstalkd.

200321.9k8](/packages/davidpersson-beanstalk)[yidas/codeigniter-queue-worker

CodeIgniter 3 Queue Worker Management Controller

9665.2k2](/packages/yidas-codeigniter-queue-worker)[tarantool/queue

PHP bindings for Tarantool Queue.

64136.2k4](/packages/tarantool-queue)

PHPackages © 2026

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