PHPackages                             happyr/mq2php-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. happyr/mq2php-bundle

ActiveSymfony-bundle

happyr/mq2php-bundle
====================

Automatically consume messages from a message queue without using a cron. Works great with SimpleBus

0.3.3(8y ago)123.7k21MITPHPPHP ^7.0

Since Jan 31Pushed 8y ago1 watchersCompare

[ Source](https://github.com/Happyr/Mq2phpBundle)[ Packagist](https://packagist.org/packages/happyr/mq2php-bundle)[ RSS](/packages/happyr-mq2php-bundle/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (12)Versions (14)Used By (1)

Mq2phpBundle for real asynchronous messages
===========================================

[](#mq2phpbundle-for-real-asynchronous-messages)

[![Latest Version](https://camo.githubusercontent.com/c62e080140ee307a38cc1cc1b2a6b660f16521f50ba5e43c11848b3b5f557933/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f4861707079722f4d713270687042756e646c652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Happyr/Mq2phpBundle/releases)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/81bc621b0f93c3f304a5282a3a859759b95c056bc37a50d3189daa37b5200d6c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4861707079722f4d713270687042756e646c652e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Happyr/Mq2phpBundle)[![Code Coverage](https://camo.githubusercontent.com/cfffa05b14e2344b98f526cfe2f51ecf77f750ecde6568f2f91ec97388da6a04/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f4861707079722f4d713270687042756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Happyr/Mq2phpBundle)[![Quality Score](https://camo.githubusercontent.com/18cc3372a36cc0649fb2eb80e9529042f5facf634f55a4645367ec560d1ac6eb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4861707079722f4d713270687042756e646c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Happyr/Mq2phpBundle)[![Total Downloads](https://camo.githubusercontent.com/d608ff31fb1e12bd9515b6846fb5622f0711383e84862ffc18adc630f9712553/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6861707079722f6d71327068702d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/happyr/mq2php-bundle)

This bundle is a bridge between [SimpleBus](http://simplebus.github.io/MessageBus/) and [mq2php](https://github.com/Happyr/mq2php). It could be used together with the [SimpleBusAsynchronousBundle](http://simplebus.github.io/AsynchronousBundle/doc/getting_started.html)to make the asynchronous messages independent of a cron job to consume the messages. Instead we utilize the power of PHP-FPM to schedule workload and resources.

Consuming messages from the queue
---------------------------------

[](#consuming-messages-from-the-queue)

We do not want to run a cron command to consume messages from the queue because of two reasons. It takes a lot of computer resources to create a new thread and if we only do one task there will be a lot of overhead. The second reason is that we want to be able to do resource scheduling. With a cronjob we say "*Consume this message at the next minute no matter your current load*". Instead we would like to do something like: "*Consume this message as soon as possible*".

The solution to these problems is nothing new. It is actually exact the problems PHP-FPM is solving. We just need a way to pull messages from the message queue and give those to PHP-FPM.

This is where [mq2php](https://github.com/Happyr/mq2php) comes in. It is a Java application that will run in the background. Java is preferred because it is build to run for ever. (Compared with PHP that should never be running for more than 30 seconds.)

Installation
------------

[](#installation)

Fetch [mq2php.jar version 0.5.0](https://github.com/Happyr/mq2php/releases) or above and start the application with:

```
java -Dexecutor=fastcgi -DmessageQueue=rabbitmq -DqueueNames=asynchronous_commands,asynchronous_events -jar mq2php.jar
```

You should consider using the init script when you using it on the production server.

Install and enable this bundle

```
composer require happyr/mq2php-bundle
```

```
class AppKernel extends Kernel
{
  public function registerBundles()
  {
    $bundles = array(
        // ...
        new Happyr\Mq2phpBundle\HappyrMq2phpBundle(),
        new SimpleBus\AsynchronousBundle\SimpleBusAsynchronousBundle(),
    }
  }
}
```

Configuration
-------------

[](#configuration)

```
// config.yml

old_sound_rabbit_mq:
  producers:
    asynchronous_commands:
      connection:       default
      exchange_options: { name: 'asynchronous_commands', type: direct }
      queue_options:    { name: 'asynchronous_commands' }

    asynchronous_events:
      connection:       default
      exchange_options: { name: 'asynchronous_events', type: direct }
      queue_options:    { name: 'asynchronous_events' }

simple_bus_rabbit_mq_bundle_bridge:
  commands:
    producer_service_id: old_sound_rabbit_mq.asynchronous_commands_producer
  events:
    producer_service_id: old_sound_rabbit_mq.asynchronous_events_producer

happyr_mq2php:
  enabled: true
  command_queue: 'asynchronous_commands' # The name of the RabbitMQ queue for commands
  event_queue: 'asynchronous_events' # The name of the RabbitMQ queue for events
  message_headers:
    fastcgi_host: localhost
    fastcgi_port: 9000
    dispatch_path: "%kernel.root_dir%/dispatch-message.php"
```

### HTTP executor

[](#http-executor)

If you are not using fastcgi (eg PHP-FPM) you may use HTTP.

```
happyr_mq2php:
  message_headers:
    http_url: https://example.com/dispatch-message.php

```

### Shell executor

[](#shell-executor)

When debugging you may want to use the shell executor. This will require more CPU resources by mq2php since starting a new process to for each message is heavy.

```
happyr_mq2php:
  message_headers:
    dispatch_path: "%kernel.root_dir%/dispatch-message.php"

```

Verify the message
------------------

[](#verify-the-message)

If you want to be sure that your message is valid and from your application you should define a secret key. This key is used to hash the message and then verify the hash on the receiving end. If you are using multiple applications you should make sure they all have the same secret key.

```
happyr_mq2php:
  secret_key: '4e10upv918856xxp7g9c'

```

Reduce the number of messages
-----------------------------

[](#reduce-the-number-of-messages)

In the SimpleBus documentation you may find that all events will be handled synchronous then asynchronous. That means that for every event your application dispatches there will be an async message. If you want to reduce the number of messages you may configure the SimpleBus AsyncBundle to only handle those events that are marked as asynchronous.

```
simple_bus_asynchronous:
  events:
    strategy: 'predefined'
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

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

Total

13

Last Release

3028d ago

PHP version history (3 changes)0.1.0PHP &gt;=5.4

0.2.0PHP ^5.6 || ^7.0

0.3.0PHP ^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/401ccc5eea13c60cf807ae982af00e368e2166e2f26d8eb541dcd881a57385bc?d=identicon)[Nyholm](/maintainers/Nyholm)

---

Top Contributors

[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (43 commits)")

### Embed Badge

![Health badge](/badges/happyr-mq2php-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/happyr-mq2php-bundle/health.svg)](https://phpackages.com/packages/happyr-mq2php-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)

PHPackages © 2026

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