PHPackages                             zlikavac32/beanstalkd-lib - 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. zlikavac32/beanstalkd-lib

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

zlikavac32/beanstalkd-lib
=========================

Beanstalkd client and worker implementation

0.5.2(5y ago)23151MITPHPPHP ^7.4CI failing

Since Apr 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/zlikavac32/beanstalkd-lib)[ Packagist](https://packagist.org/packages/zlikavac32/beanstalkd-lib)[ RSS](/packages/zlikavac32-beanstalkd-lib/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (8)Versions (9)Used By (1)

Beanstalkd lib
==============

[](#beanstalkd-lib)

[![Build Status](https://camo.githubusercontent.com/e2002f443ee026d89184825a4ed0c92a36148025902a41c4f09bc09dc423a364/68747470733a2f2f7472617669732d63692e6f72672f7a6c696b6176616333322f6265616e7374616c6b642d6c69622e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/zlikavac32/beanstalkd-lib)

A different Beanstalkd client library.

Table of contents
-----------------

[](#table-of-contents)

1. [Introduction](#introduction)
    1. [Protocol](#protocol)
    2. [Client](#client)
    3. [Framework agnostic](#framework-agnostic)
    4. [Various signal handling strategies](#carious-signal-handling-strategies)
    5. [Graceful exit support](#graceful-exit-support)
    6. [Oriented towards decorators](#oriented-towards-decorators)
    7. [Auto-touch job](#auto-touch-job)
    8. [Tube specific configuration](#tube-specific-configuration)
2. [Installation](#installation)
3. [Usage](#usage)
    1. [Configuration](#configuration)
    2. [Producers](#producers)
    3. [Workers](#workers)
4. [Examples](#examples)

Introduction
------------

[](#introduction)

Library is composed of two layers, `Protocol` and `Client`. `Protocol` is one-to-one mapping of Beanstalkd commands, and `Client` is higher level API which decomposes functionality into multiple interfaces.

Job dispatcher/runner functionality is also provided, as well as support for signal handling.

### Protocol

[](#protocol)

Interface for the protocol is `Zlikavac32\BeanstalkdLib\Protocol` and default implementation is provided as `Zlikavac32\BeanstalkdLib\Protocol\ProtocolOverSocket`.

Methods represent Beanstalkd commands as they are defined in the protocol. That means that there are no default values in the methods. Every distinct Beanstalkd error has it's own exception to make error recovery easier.

### Client

[](#client)

Client is higher level API for Beanstalkd, that consists of three main interfaces:

- `Zlikavac32\BeanstalkdLib\Client` - interface towards generic server commands
- `Zlikavac32\BeanstalkdLib\TubeHandle` - interface towards tube related commands
- `Zlikavac32\BeanstalkdLib\JobHandle` - interface towards job related commands

To express higher level API, interface methods are no longer directly mapped to Beanstalkd commands.

Status responses have their own classes which expose readable interface to those values, and values themselves are strictly typed.

Default implementations are backend by `Protocol` and are provided in:

- `Zlikavac32\BeanstalkdLib\Client\ProtocolClient`
- `Zlikavac32\BeanstalkdLib\Client\ProtocolTubeHandle`
- `Zlikavac32\BeanstalkdLib\Client\ProtocolJobHandle`

### Framework agnostic

[](#framework-agnostic)

Library itself is agnostic to any framework. Adapters are currently provided only for Symfony. Where possible, library is also agnostic to other libraries and extensions. For example, yaml parsing, socket access and json serialization are defined through interfaces required by this library, and adapters are provided for extensions and libraries.

### Various signal handling strategies

[](#various-signal-handling-strategies)

`Zlikavac32\BeanstalkdLib\SignalHandlerInstaller` installs injected `Zlikavac32\BeanstalkdLib\InterruptHandler` to handle `SIGINT`, `SIGTERM` and `SIGQUIT`.

Existing handling strategies are:

- `Zlikavac32\BeanstalkdLib\InterruptHandler\DoNothingInterruptHandler` - just ignores signal
- `Zlikavac32\BeanstalkdLib\InterruptHandler\GracefulExitInterruptHandler` - mark that graceful exit is in progress
- `Zlikavac32\BeanstalkdLib\InterruptHandler\HardInterruptHandler` - on second signal throws interrupt exception
- `Zlikavac32\BeanstalkdLib\InterruptHandler\TimeoutHardInterruptHandler` - schedules interrupt exception to be thrown in N seconds

### Graceful exit support

[](#graceful-exit-support)

`Zlikavac32\BeanstalkdLib\GracefulExit` can be used to inspect whether graceful exit is in progress, and if so, no more processing should be done. By default, graceful exit inspection is provided through `Zlikavac32\BeanstalkdLib\InterruptHandler\GracefulExitInterruptHandler`.

Job dispatcher and protocol inspect value to break from waiting.

### Oriented towards decorators

[](#oriented-towards-decorators)

Since the idea is to keep classes thin, more functionality is provided by decorating original service.

For example, sockets can be made lazy with `Zlikavac32\BeanstalkdLib\Socket\LazySocket` and have exclusive access (due to the signals) with `Zlikavac32\BeanstalkdLib\Socket\ExclusiveAccessSocket`.

### Auto-touch job

[](#auto-touch-job)

`Zlikavac32\BeanstalkdLib\Runner\AutoTouchRunner` is runner decorator that will asynchronously touch job if his time to run is running out.

### Tube specific configuration

[](#tube-specific-configuration)

Default values are defined on tube configuration, which client uses when no other value is provided. That means that different tubes can have different default values, like time to run, or serializer used.

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

[](#installation)

Recommended installation is through Composer.

```
composer require zlikavac32/beanstalkd-lib

```

Usage
-----

[](#usage)

Next, we'll explore configuration and usage.

### Configuration

[](#configuration)

Provided protocol implementation (`Zlikavac32\BeanstalkdLib\Protocol\ProtocolOverSocket`) uses `Zlikavac32\BeanstalkdLib\Socket` to establish connection with the server. Provided adapter is for `sockets` PHP extension.

```
$socket = new NativePHPSocket(60000000);
```

Original socket can be decorated so that it's, for example, lazily loadad.

```
$socket = new LazySocket($socket);
```

Provided protocol implementation also requires `Zlikavac32\BeanstalkdLib\YamlParser` for protocol parsing. Adapter is provided Symfony YAML component.

```
$yamlParser = new SymfonyYamlParser();
```

One last thing that protocol requires is graceful exit object (instance of `Zlikavac32\BeanstalkdLib\GracefulExit`) to determine whether we should break from waiting.

```
$gracefulExit = new GracefulExitInterruptHandler();
```

Now we can create our protocol.

```
$protocol = new ProtocolOverSocket(
    $socket->open('127.0.0.1', 11300),
    $gracefulExit,
    $yamlParser
);
```

Protocol on it's own does not bring any great benefit to our code, and that's where `Zlikavac32\BeanstalkdLib\Client` comes into play.

Since client abstracts tube access, we can reduce number of use tube commands by decorating protocol to be state aware.

```
$protocol = new StateAwareProtocol($protocol);
```

Next we need tube configuration for each tube that we want the system to know about. Every tube configuration requires serializer implemented as `Zlikavac32\BeanstalkdLib\Serializer`. For domain objects custom serializers can be implemented, or a generic serializer like `Zlikavac32\BeanstalkdLib\Adapter\PHP\Json\NativePHPJsonSerializer` can be used.

```
$jsonSerializer = new NativePHPJsonSerializer(true);
$fooTubeConfiguration = new StaticTubeConfiguration(0, 1024, 300, 3600, $jsonSerializer)
```

Now we can create our client. Client requires protocol tube purger instance, and a map of known tube configurations where the key is a tube name and the value is a tube configuration.

```
$protocolTubePurger = new IterativeProtocolTubePurger();

$client = new ProtocolClient($protocol, $protocolTubePurger, new Map([
    'foo' => $fooTubeConfiguration,
]));
```

### Producers

[](#producers)

To put a job into the queue, we retrieve correct tube and put a job in it.

```
$fooTube = $client->tube('foo');

$fooTube->put([1, 2, 3, 4]);
```

### Workers

[](#workers)

To reserve a job, we call `reserve()` on the client.

```
$reservedJob = $client->reserve();
```

Reserved job can then be manipulated. Configured tube serializer is used to deserialize payload.

```
$jobId = $reservedJob->id();
$deserializedPayload = $reservedJob->payload();

$reservedJob->delete();
```

To make things easier, job dispatcher is provided in `Zlikavac32\BeanstalkdLib\JobDispatcher\TubeMapJobDispatcher`. Complete configuration, with signal handling, can be found in [examples/worker\_producer](/examples/worker_producer)

Examples
--------

[](#examples)

You can see more examples with code comments in [examples](/examples).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~64 days

Recently: every ~111 days

Total

8

Last Release

2122d ago

PHP version history (2 changes)0.1.0PHP ^7.1

0.5.0PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b47ffc503d7c4536136bc08ed1185682bec5789108bd7a2cf7edfee98994dfef?d=identicon)[zlikavac32](/maintainers/zlikavac32)

---

Top Contributors

[![zlikavac32](https://avatars.githubusercontent.com/u/1078270?v=4)](https://github.com/zlikavac32 "zlikavac32 (74 commits)")

---

Tags

beanstalkdjob-queuepcntlphpworkerqueuejobbeanstalkdworker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zlikavac32-beanstalkd-lib/health.svg)

```
[![Health](https://phpackages.com/badges/zlikavac32-beanstalkd-lib/health.svg)](https://phpackages.com/packages/zlikavac32-beanstalkd-lib)
```

###  Alternatives

[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)[tarantool/queue

PHP bindings for Tarantool Queue.

64136.2k4](/packages/tarantool-queue)[foxxmd/laravel-elasticbeanstalk-queue-worker

Deploy your Laravel application as a queue worker on AWS ElasticBeanstalk

5493.5k](/packages/foxxmd-laravel-elasticbeanstalk-queue-worker)[pmatseykanets/artisan-beans

Easily manage your Beanstalkd job queues right from the Laravel artisan command

4482.1k](/packages/pmatseykanets-artisan-beans)

PHPackages © 2026

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