PHPackages                             skydiablo/async-event-dispatcher-bundle - 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. skydiablo/async-event-dispatcher-bundle

ActiveSymfony-bundle[Queues &amp; Workers](/categories/queues)

skydiablo/async-event-dispatcher-bundle
=======================================

Handle all your events in an asynchronous way

1.1(9y ago)21.9kMITPHPPHP &gt;=7.0

Since Sep 13Pushed 9y ago1 watchersCompare

[ Source](https://github.com/skydiablo/AsyncEventDispatcherBundle)[ Packagist](https://packagist.org/packages/skydiablo/async-event-dispatcher-bundle)[ RSS](/packages/skydiablo-async-event-dispatcher-bundle/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

AsyncEventDispatcher
====================

[](#asynceventdispatcher)

The AsyncEventDispatcher is a symfony bundle that provides an easy way for asynchronous event handling. Handle all your existing or new events in an async style. Just define your event handler as usual and run it in an async scope.

A) Downloading the Bundle
-------------------------

[](#a-downloading-the-bundle)

Open your command line, navigate to your project directory and execute the following command to download the latest stable version of this bundle:

```
$ composer require skydiablo/async-event-dispatcher-bundle

```

This command requires you to have Composer installed globally, as explained in the [installation chapter of the Composer documentation](https://getcomposer.org/).

B) Enabling the Bundle
----------------------

[](#b-enabling-the-bundle)

Enable the bundle by adding the following line in the `app/AppKernel.php`file of your project:

```
// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new SkyDiablo\AsyncEventDispatcherBundle\AsyncEventDispatcherBundle(),
        );

        // ...
    }
}

```

C) Configuring the Bundle
-------------------------

[](#c-configuring-the-bundle)

There's currently only one event queue implemented: Amazon AWS SQS. If you need another one, feel free to implement it and make a pull request.

```
async_event_dispatcher:
    queue:
        awssqs:
            queue_url: http://...AWS...QUEUE...URL
            long_polling_timeout: 10 # some time in seconds...
            sqs_client: aws_sqs_client_service_name

```

D) Usage
--------

[](#d-usage)

- Just create your events and listener like documented [here](http://symfony.com/doc/current/event_dispatcher.html)
- Instead of tagging your listener like this: `kernel.event_listener`, just add the '.async' suffix: `kernel.event_listener.async`

    - The same applies to subscriber tagging: `kernel.event_subscriber.async`
- Publish your event serializer

    - For simple and static events, just use the `GenericEventSerializer`. Define your serializer for events like this:

        ```
          services:
              your_custom_serializer:
                  class: SkyDiablo\AsyncEventDispatcherBundle\Serializer\GenericEventSerializer
                  tags:
                      - { name: async_event_serializer, event: your_simple_event_name }

        ```
    - Trickier events with complex objects or doctrine entities need a custom event serializer. You can choose how you want to serialize and deserialize the event data. Create your serializer and implement the `SkyDiablo\AsyncEventDispatcherBundle\Serializer\EventSerializerInterface` interface. Define this new serializer as explained above.

        ```
          class FooEventSerializer implements EventSerializerInterface
          {

              /**
               * @var FooRepository
               */
              private $fooRepository;

              /**
               * FooEventSerializer constructor.
               * @param FooRepository $fooRepository
               */
              public function __construct(FooRepository $fooRepository)
              {
                  $this->fooRepository = $fooRepository;
              }

              /**
               * @param Event $event
               * @param string $eventName
               * @return QueueItemInterface
               */
              public function serialize(Event $event, $eventName)
              {
                  if ($event instanceof FooEvent) {
                      return new QueueItem($eventName, $event->getFoo()->getId()); // just serialize the entity id
                  }
              }

              /**
               * @param QueueItemInterface $queueItem
               * @return Event
               */
              public function deserialize(QueueItemInterface $queueItem)
              {
                  $fooId = (int)$queueItem->getData(); // "getData()" contains the result from serialize function
                  if($fooId) { // a valid number greater zero?
                      if($foo = $this->fooRepository->getById($fooId)) { // try to load foo entity by id
                          return new FooEvent($foo); // create the event object that will be triggered async
                      }
                  }
              }
          }

        ```

    From now on, all your listeners/subscribers which are tagged for async handling will run in an async scope. Attention: events without serializers will be ignored and are never handled!
- The core of the async event handling is a CLI command. Run this command in cyclic interval (i. e. cronjob-style):

    ```
         $ php bin/console async_event_dispatcher --iterate-amount 5

    ```

    This command will handle 5 events in this run, the default is set to handle 10 events in one run.

Thats it!

E) Extra
--------

[](#e-extra)

In some situations you might need the scope of the request where the event was thrown. To use the scope of that request in the async event handler, do the following:

```
/**
 * Inject in a propper way
 * @var \Symfony\Component\HttpFoundation\RequestStack
 */
private $requestStack;

public function someEventHandler(YourEvent $event) {
    // You can request the current request in the async event handler like this
    $currentRequest = $this->requestStack->getCurrentRequest();
}

```

There are some simple solutions:

- Implement the `SkyDiablo\AsyncEventDispatcherBundle\Event\AsyncRequestScopeEventInterface` interface in your custom event
- Define request scope in the subscriber config:

    ```
     class ExceptionSubscriber implements EventSubscriberInterface
     {
       public static function getSubscribedEvents()
       {
           // return the subscribed events, their methods and priorities
           return array(
              KernelEvents::EXCEPTION => array(
                  array('processException', 10, true), // The third parameter "true" activates the request scope
              )
           );
       }

    ```
- Define the request scope within the event listener tag:

    ```
      # app/config/services.yml
      services:
          app.exception_listener:
              class: AppBundle\EventListener\ExceptionListener
              tags:
                  # set "async-request" to "true" or "false"
                  - { name: kernel.event_listener.async, event: kernel.exception, async-request: true }

    ```

What if you can't or don't want to handle an event asynchronously? Just implement this interface:

```
    SkyDiablo\AsyncEventDispatcherBundle\Event\AsyncEventInterface

```

and return "false" at the `isAllowAsync` function. Then this event will never be called asynchronously!

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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 ~162 days

Total

2

Last Release

3416d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/956423?v=4)[Volker](/maintainers/skydiablo)[@skydiablo](https://github.com/skydiablo)

---

Top Contributors

[![skydiablo](https://avatars.githubusercontent.com/u/956423?v=4)](https://github.com/skydiablo "skydiablo (29 commits)")

---

Tags

eventasync

### Embed Badge

![Health badge](/badges/skydiablo-async-event-dispatcher-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/skydiablo-async-event-dispatcher-bundle/health.svg)](https://phpackages.com/packages/skydiablo-async-event-dispatcher-bundle)
```

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k133.8M413](/packages/amphp-amp)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

92553.8M213](/packages/revolt-event-loop)[icicleio/icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

1.1k152.2k15](/packages/icicleio-icicle)[recoil/recoil

Asynchronous coroutines for PHP 7.

79062.4k7](/packages/recoil-recoil)[recoil/react

Integrate Recoil with ReactPHP.

32286.7k12](/packages/recoil-react)[async-interop/event-loop

An event loop interface for interoperability.

1696.1k4](/packages/async-interop-event-loop)

PHPackages © 2026

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