PHPackages                             myclabs/work - 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. myclabs/work

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

myclabs/work
============

Work queue library letting you run background tasks using a generic abstraction

0.4.0(12y ago)622944[1 issues](https://github.com/myclabs/Work/issues)MITPHPPHP &gt;=5.4.0

Since Sep 25Pushed 10y ago7 watchersCompare

[ Source](https://github.com/myclabs/Work)[ Packagist](https://packagist.org/packages/myclabs/work)[ RSS](/packages/myclabs-work/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

[![Build Status](https://camo.githubusercontent.com/f0ed8276c3eb19f3f0d71c69dbf98ec536cb8ff58242dbfa1da3511b77aa1833/68747470733a2f2f7472617669732d63692e6f72672f6d79636c6162732f576f726b2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/myclabs/Work)[![Coverage Status](https://camo.githubusercontent.com/4bb4594d16d8d80173ad5ed48210cfbc99c39a0969e8b5ab4c42806c8bb8d1f1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6d79636c6162732f576f726b2f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/myclabs/Work?branch=master)[![Scrutinizer Quality Score](https://camo.githubusercontent.com/c7ac307bb24f9751c9d0e055f2b7267eb0b51cf21cf1559a7395ad7e580a28a7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d79636c6162732f576f726b2f6261646765732f7175616c6974792d73636f72652e706e673f733d31623637353763313337646434326533383364633435396564663437346263666462633933356265)](https://scrutinizer-ci.com/g/myclabs/Work/)[![Total Downloads](https://camo.githubusercontent.com/7bdacda207f04db5f4905f08c69a31c1c33f2a39c8628b3cf785dc1289afbc1d/68747470733a2f2f706f7365722e707567782e6f72672f6d79636c6162732f776f726b2f646f776e6c6f6164732e737667)](https://packagist.org/packages/myclabs/work)

**MyCLabs\\Work is a work queue library letting you run tasks in background using a generic abstraction.**

It's intent is to be compatible with classic work queue solutions (RabbitMQ, Beanstalkd, …) while offering a high level abstraction.

Current implementations:

- InMemory: synchronous implementation, task are executed directly (useful for tests or dev environments)
- [RabbitMQ](https://www.rabbitmq.com/)
- [Beanstalkd](https://kr.github.io/beanstalkd/)

Feel free to contribute and submit other implementations (Gearman, …).

Extended guides:

- [The InMemory adapter](doc/InMemory.md)
- [The RabbitMQ adapter](doc/RabbitMQ.md)
- [The Beanstalkd adapter](doc/Beanstalkd.md)
- [Listening to events](doc/Events.md)

How it works
------------

[](#how-it-works)

In you code (HTTP request for example), you can run a task in background:

```
$workDispatcher = new RabbitMQWorkDispatcher(/* parameters */);
$workDispatcher->run(new MyTask());
```

Separately, you set up a worker to run continuously on the command line (like a deamon):

```
$ php my-worker.php
```

This worker simply calls:

```
// my-worker.php
$worker = new RabbitMQWorker(/* parameters */);
// Will loop continuously and execute tasks
$worker->work();
```

### Defining tasks

[](#defining-tasks)

Define a task:

```
class BigComputation implements MyCLabs\Work\Task\Task
{
    public $parameter1;
}
```

And define the code that executes the task:

```
class BigComputationExecutor implements MyCLabs\Work\TaskExecutor\TaskExecutor
{
    public function execute(Task $task)
    {
        if (! $task instanceof BigComputation) {
            throw new \Exception("Invalid task type provided");
        }
        // Perform the action (here we just multiply the parameter by 2)
        return $task->parameter1 * 2;
    }
}
```

Execute a task and wait for its result
--------------------------------------

[](#execute-a-task-and-wait-for-its-result)

The `run($task)` method runs a task in background.

If you want to wait for the result of that task, you have to use a WorkDispatcher that implements the `\MyCLabs\Work\Dispatcher\SynchronousWorkDispatcher` interface. For example, the RabbitMQ adapter implements this interface.

That interface offers the `runAndWait` method:

```
interface SynchronousWorkDispatcher extends WorkDispatcher
{
    /**
     * Run a task in background.
     *
     * You can use $wait to wait a given time for the task to complete.
     * If the task hasn't finished during this time, $timedout will be
     * called and this method will return.
     * If the task has finished, $completed will be called.
     *
     * @param Task     $task
     * @param int      $wait      Number of seconds to wait for the task to complete.
     *                            If 0, doesn't wait.
     * @param callable $completed Called (if $wait > 0) when the task has completed.
     * @param callable $timedout  Called (if $wait > 0) if we hit the timeout while
     *                            waiting.
     * @param callable $errored   Called (if $wait > 0) if the task errors. Takes 1
     *                            parameter which is the exception.
     *
     * @return void No results
     */
    public function runAndWait(
        Task $task,
        $wait = 0,
        callable $completed = null,
        callable $timedout = null,
        callable $errored = null
    );
}
```

Read more
---------

[](#read-more)

Read more in [the docs](doc/).

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

[](#contributing)

You can run the tests with PHPUnit:

```
$ composer install
$ vendor/bin/phpunit
```

Some functional tests need external programs like RabbitMQ or Beanstalkd. For practical reasons, you can boot a VM very quickly using Vagrant and the included configuration. You can then run the tests in the VM:

```
$ vagrant up
$ vagrant ssh
$ cd /vagrant
$ composer install
$ vendor/bin/phpunit
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 98.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 ~82 days

Total

4

Last Release

4414d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/329a6111724074f5388e95dd41a03ccf3c43f4bfe1ecf27c94c9efc6f7823228?d=identicon)[mnapoli](/maintainers/mnapoli)

![](https://www.gravatar.com/avatar/8220feb8a3d9f1df987987c33494da696aca6929179a6281cdbe45623fcbec0f?d=identicon)[myclabs](/maintainers/myclabs)

---

Top Contributors

[![mnapoli](https://avatars.githubusercontent.com/u/720328?v=4)](https://github.com/mnapoli "mnapoli (78 commits)")[![jdreesen](https://avatars.githubusercontent.com/u/424602?v=4)](https://github.com/jdreesen "jdreesen (1 commits)")

---

Tags

rabbitmqtaskdistributedworkwork queue

### Embed Badge

![Health badge](/badges/myclabs-work/health.svg)

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

###  Alternatives

[php-amqplib/php-amqplib

Formerly videlalvaro/php-amqplib. This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.

4.6k129.9M974](/packages/php-amqplib-php-amqplib)[php-amqplib/rabbitmq-bundle

Integrates php-amqplib with Symfony &amp; RabbitMq. Formerly emag-tech-labs/rabbitmq-bundle, oldsound/rabbitmq-bundle.

1.2k20.7M68](/packages/php-amqplib-rabbitmq-bundle)[bunny/bunny

Performant pure-PHP AMQP (RabbitMQ) non-blocking ReactPHP library

7466.7M42](/packages/bunny-bunny)[enqueue/enqueue-bundle

Message Queue Bundle

27515.9M41](/packages/enqueue-enqueue-bundle)[enqueue/enqueue

Message Queue Library

19020.5M62](/packages/enqueue-enqueue)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2792.4M7](/packages/bschmitt-laravel-amqp)

PHPackages © 2026

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