PHPackages                             clivern/chunk - 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. clivern/chunk

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

clivern/chunk
=============

Asynchronous Task Queue Based on Distributed Message Passing for PHP.

2.0.1(5y ago)378.9k↓20%1[1 issues](https://github.com/Clivern/Chunk/issues)[3 PRs](https://github.com/Clivern/Chunk/pulls)MITPHPPHP &gt;=7.2

Since Mar 14Pushed 4d agoCompare

[ Source](https://github.com/Clivern/Chunk)[ Packagist](https://packagist.org/packages/clivern/chunk)[ Docs](https://github.com/clivern/chunk)[ GitHub Sponsors](https://github.com/clivern)[ RSS](/packages/clivern-chunk/feed)WikiDiscussions 2.x Synced 2d ago

READMEChangelog (10)Dependencies (5)Versions (14)Used By (0)

 [![chunk Logo](/assets/img/gopher.png?v=2.0.1)](/assets/img/gopher.png?v=2.0.1)

### Chunk

[](#chunk)

Asynchronous Task Queue Based on Distributed Message Passing for PHP

 [ ![](https://github.com/clivern/chunk/actions/workflows/php.yml/badge.svg) ](https://github.com/clivern/chunk/actions/workflows/php.yml) [ ![](https://camo.githubusercontent.com/4b0ffa286c1b30de489ee3e7fb8dd8731044ca3471c8a52688c8ba6a75d27616/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56657273696f6e2d322e302e312d7265642e737667) ](https://packagist.org/packages/clivern/chunk) [ ![](https://camo.githubusercontent.com/128887c51de1fa9a4ddc82f3643a3a773f1ad69e88f9ed68ffe4ddcc8667cc6a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c4943454e53452d4d49542d6f72616e67652e737667) ](https://github.com/Clivern/Chunk/blob/master/LICENSE)

Documentation
-------------

[](#documentation)

### Installation:

[](#installation)

To install the package via `composer`, use the following:

```
$ composer require clivern/chunk
```

This command requires you to have `composer` installed globally.

### Basic Usage:

[](#basic-usage)

First create event handlers. Chunk supports these events

- `EventInterface::ON_MESSAGE_RECEIVED_EVENT`
- `EventInterface::ON_MESSAGE_FAILED_EVENT`
- `EventInterface::ON_MESSAGE_HANDLED_EVENT`
- `EventInterface::ON_MESSAGE_SENT_EVENT`
- `EventInterface::ON_MESSAGE_SEND_FAILURE_EVENT`

```
use Clivern\Chunk\Contract\MessageInterface;
use Clivern\Chunk\Contract\EventInterface;
use Clivern\Chunk\Core\EventHandler;

class MessageReceivedEvent implements EventInterface
{
    /**
     * {@inheritdoc}
     */
    public function getType(): string
    {
        return EventInterface::ON_MESSAGE_RECEIVED_EVENT;
    }

    /**
     * {@inheritdoc}
     */
    public function invoke(MessageInterface $message, $exception = null)
    {
        var_dump(sprintf('Message Received Event: %s', (string) $message));
    }
}

class MessageFailedEvent implements EventInterface
{
    /**
     * {@inheritdoc}
     */
    public function getType(): string
    {
        return EventInterface::ON_MESSAGE_FAILED_EVENT;
    }

    /**
     * {@inheritdoc}
     */
    public function invoke(MessageInterface $message, $exception = null)
    {
        var_dump(sprintf('Message Failed Event: %s', (string) $message));
    }
}

class MessageHandledEvent implements EventInterface
{
    /**
     * {@inheritdoc}
     */
    public function getType(): string
    {
        return EventInterface::ON_MESSAGE_HANDLED_EVENT;
    }

    /**
     * {@inheritdoc}
     */
    public function invoke(MessageInterface $message, $exception = null)
    {
        var_dump(sprintf('Message Handled Event: %s', (string) $message));
    }
}

class MessageSentEvent implements EventInterface
{
    /**
     * {@inheritdoc}
     */
    public function getType(): string
    {
        return EventInterface::ON_MESSAGE_SENT_EVENT;
    }

    /**
     * {@inheritdoc}
     */
    public function invoke(MessageInterface $message, $exception = null)
    {
        var_dump(sprintf('Message Sent Event: %s', (string) $message));
    }
}

class MessageSendFailureEvent implements EventInterface
{
    /**
     * {@inheritdoc}
     */
    public function getType(): string
    {
        return EventInterface::ON_MESSAGE_SEND_FAILURE_EVENT;
    }

    /**
     * {@inheritdoc}
     */
    public function invoke(MessageInterface $message, $exception = null)
    {
        var_dump(sprintf('Message Send Failure Event: %s', (string) $message));
        var_dump(sprintf('Error raised: %s', $exception->getMessage()));
    }
}

$eventHandler = new EventHandler();
$eventHandler->addEvent(new MessageReceivedEvent())
             ->addEvent(new MessageFailedEvent())
             ->addEvent(new MessageHandledEvent())
             ->addEvent(new MessageSendFailureEvent())
             ->addEvent(new MessageSentEvent());
```

Then create async message handlers, Each handler has a unique key so chunk can map the message to the appropriate handler.

In the following code, we create a handler to process any message with type `serviceA.processOrder`.

```
use Clivern\Chunk\Contract\MessageHandlerInterface;
use Clivern\Chunk\Contract\MessageInterface;
use Clivern\Chunk\Core\Mapper;

class ProcessOrderMessageHandler implements MessageHandlerInterface
{
    /**
     * Invoke Handler.
     */
    public function invoke(MessageInterface $message): MessageHandlerInterface
    {
        var_dump(sprintf('Process Message: %s', (string) $message));

        return $this;
    }

    /**
     * onSuccess Event.
     *
     * @return void
     */
    public function onSuccess()
    {
        var_dump('Operation Succeeded');
    }

    /**
     * onFailure Event.
     *
     * @return void
     */
    public function onFailure()
    {
        var_dump('Operation Failed');
    }

    /**
     * Handler Type.
     */
    public function getType(): string
    {
        return 'serviceA.processOrder';
    }
}

$mapper = new Mapper();
$mapper->addHandler(new ProcessOrderMessageHandler());
```

Then create an instance of the message broker.

```
use Clivern\Chunk\Core\Broker\RabbitMQ;

$broker = new RabbitMQ('127.0.0.1', 5672, 'guest', 'guest');
```

Now you can run listener daemon

```
use Clivern\Chunk\Core\Listener;

$listener = new Listener($broker, $eventHandler, $mapper);
$listener->connect();
$listener->listen();
$listener->disconnect();
```

And start sending a message from a different process

```
use Clivern\Chunk\Core\Sender;
use Clivern\Chunk\Core\Message;

$sender = new Sender($broker, $eventHandler);

$sender->connect();

$message = new Message();
$message->setId(1)
        ->setUuid('f9714a92-2129-44e6-9ef4-8eebc2e33958') // or leave & chunk will generate a uuid
        ->setPayload('something')
        ->setHandlerType('serviceA.processOrder'); // same as the one defined in ProcessOrderMessageHandler class -> getType method

$sender->send($message);
$sender->disconnect();
```

For a complete working examples, please check [this folder](/examples).

Versioning
----------

[](#versioning)

For transparency into our release cycle and in striving to maintain backward compatibility, Chunk is maintained under the [Semantic Versioning guidelines](https://semver.org/) and release process is predictable and business-friendly.

See the [Releases section of our GitHub project](https://github.com/clivern/chunk/releases) for changelogs for each release version of Chunk. It contains summaries of the most noteworthy changes made in each release.

Bug tracker
-----------

[](#bug-tracker)

If you have any suggestions, bug reports, or annoyances please report them to our issue tracker at

Security Issues
---------------

[](#security-issues)

If you discover a security vulnerability within Chunk, please send an email to

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

[](#contributing)

We are an open source, community-driven project so please feel free to join us. see the [contributing guidelines](CONTRIBUTING.md) for more details.

License
-------

[](#license)

© 2020, clivern. Released under [MIT License](https://opensource.org/licenses/mit-license.php).

**Chunk** is authored and maintained by [@clivern](http://github.com/clivern).

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance64

Regular maintenance activity

Popularity34

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 72.9% 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

Recently: every ~167 days

Total

11

Last Release

1474d ago

Major Versions

0.0.1 → 1.0.02020-08-16

1.6.0 → 2.0.02021-06-24

PHP version history (2 changes)0.0.1PHP &gt;=7.0

1.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/6972371682cd4255285c19cb35f05151468506019b13374b14f305f5926107d6?d=identicon)[clivern](/maintainers/clivern)

---

Top Contributors

[![Clivern](https://avatars.githubusercontent.com/u/1634427?v=4)](https://github.com/Clivern "Clivern (43 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (15 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (1 commits)")

---

Tags

asyncchunkclivernhacktoberfestphp-asyncphp-sdkqueuerabbitmqtask-queuechunkclivern

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/clivern-chunk/health.svg)

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

###  Alternatives

[illuminate/queue

The Illuminate Queue package.

21332.6M1.6k](/packages/illuminate-queue)[magento/community-edition

Magento 2 (Open Source)

12.2k53.6k13](/packages/magento-community-edition)[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2822.5M7](/packages/bschmitt-laravel-amqp)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[hyperf/amqp

A amqplib for hyperf.

231.3M73](/packages/hyperf-amqp)[convenia/pigeon

3334.8k](/packages/convenia-pigeon)

PHPackages © 2026

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