2017 © Pedro Peláez
 

symfony-bundle deferred-event-bundle

Defer your events to another process (via FastCGI)

image

fervo/deferred-event-bundle

Defer your events to another process (via FastCGI)

  • Tuesday, April 10, 2018
  • by magnusnordlander
  • Repository
  • 9 Watchers
  • 43 Stars
  • 53,540 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 9 Forks
  • 4 Open issues
  • 13 Versions
  • 4 % Grown

The README.md

FervoDeferredEventBundle

This bundle allows you to run asynchronous background processes in PHP. You don't need a PHP-daemon nor do you have to create a new php process for each job (which is expensive). We use PHP-FPM because it solves the performance and stability issues for us., (*1)

I wrote a blog entry with the reasoning behind this bundle, which you may want to read., (*2)

Caveat

This project is no longer actively developed by Fervo. We're still willing to merge PRs, but we're moving away from this internally. If you have a vested interest in this project and want to adopt it, contact us at magnus@fervo.se., (*3)

Usage

You can defer events in two ways. You can decide when you dispatch an event that it should be deferred or you could let some listeners to decide if they should be deferred or not. In both cases we dispatch the event and put the job on a message queue., (*4)

As if by magic, at some later time, a worker will dispatch your event to your listeners. Pretty much the only caveats you'll need to keep in mind is that it is in another process, and that the code isn't executing in the request scope anymore., (*5)

Let the listeners decide

Just tag your listener with fervo_deferred_event.listener instead of kernel.event_listener, and the bundle will do the rest. Simple as pie., (*6)

Let the publisher decide

If you want all listeners to a event to be executed in a different thread you must wrap your Event in a DeferEvent. Then use the event dispatcher and dispatch 'fervo.defer'., (*7)

$event = new DeferEvent('foo.action', new MyEvent());
$this->get('event_dispatcher')->dispatch('fervo.defer', $event);

Setup

Server software

You need to install a message queue and a worker. The worker will pull jobs from the message queue and initiate the execution., (*8)

Currently we do support all message queues that support AMQP and Sidekiq., (*9)

Here is a list of workers:, (*10)

Symfony setup

Add the bundle to your composer file, as well as well as your AppKernel. Configure the bundle as follows:, (*11)

# Sidekiq example
fervo_deferred_event:
    backend:
        type: sidekiq
        sidekiq_client_service: sidekiq_client

# Java/AMQP example:
fervo_deferred_event:
    backend:
        type: amqp
        amqp_config:
            host: "localhost"             #default
            port: 5672                    #default
            batch_publishing: false       #can only be true if you are using videlalvaro/php-amqplib v.2.2.0 or above
        message_headers:
            fastcgi_host: "localhost"     #default
            fastcgi_port: 9000            #default

You do also need to setup one of the following (depending on you backend type):, (*12)

Error handling

The Java worker we take care of errors. When a worker unexpectedly terminates we will save the message and the error message on a separate queue. You may subscribe to that queue to log the error and to retry executing the job., (*13)

The Versions

10/04 2018

dev-develop

dev-develop

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

10/04 2018

dev-master

9999999-dev

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

10/04 2018

0.3.0

0.3.0.0

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

10/04 2018

dev-release/0.3.0

dev-release/0.3.0

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

10/04 2018

0.2.2

0.2.2.0

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

26/03 2018

0.2.1

0.2.1.0

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

26/03 2018

dev-hotfix/0.2.2

dev-hotfix/0.2.2

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

27/09 2017

0.2.0

0.2.0.0

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

27/09 2017

dev-hotfix/0.2.1

dev-hotfix/0.2.1

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

27/09 2017

dev-release/0.2.0

dev-release/0.2.0

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

11/11 2015

0.1.0

0.1.0.0

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

11/08 2014

dev-debug

dev-debug

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires

 

24/11 2013

dev-delay-support

dev-delay-support

Defer your events to another process (via FastCGI)

  Sources   Download

MIT

The Requires