Download the PHP package fervo/deferred-event-bundle without Composer
On this page you can find all versions of the php package fervo/deferred-event-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fervo/deferred-event-bundle
More information about fervo/deferred-event-bundle
Files in fervo/deferred-event-bundle
Package deferred-event-bundle
Short Description Defer your events to another process (via FastCGI)
License MIT
Informations about the package deferred-event-bundle
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.
I wrote a blog entry with the reasoning behind this bundle, which you may want to read.
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 [email protected].
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.
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.
Let the listeners decide
Just tag your listener with instead of , and the bundle will do the rest. Simple as pie.
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'.
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.
Currently we do support all message queues that support AMQP and Sidekiq.
Here is a list of workers:
- fervo/deferred-event-worker written in Ruby.
- HappyR/DeferredEventJavaWorker written in Java.
Symfony setup
Add the bundle to your composer file, as well as well as your AppKernel. Configure the bundle as follows:
You do also need to setup one of the following (depending on you backend type):
- musicglue/sidekiq-job-pusher. Set up a client service, and pass it into the configuration.
- videlalvaro/php-amqplib. Just add it to your composer.json.
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.
All versions of deferred-event-bundle with dependencies
symfony/event-dispatcher Version ~3.0
symfony/framework-bundle Version ~3.0
symfony/console Version ~3.0