Download the PHP package bunny/bunny without Composer
On this page you can find all versions of the php package bunny/bunny. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
All versions of bunny with dependencies
Informations about the package bunny
Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library
BunnyPHP requires PHP 7.1 and newer.
Add as Composer dependency:
You might ask if there isn't a library/extension to connect to AMQP broker (e.g. RabbitMQ) already. Yes, there are multiple options:
- ext-amqp - PHP extension
- php-amqplib - pure-PHP AMQP protocol implementation
- react-amqp - ext-amqp binding to ReactPHP
Why should you want to choose BunnyPHP instead?
You want nice idiomatic PHP API to work with (I'm looking at you, php-amqplib). BunnyPHP interface follows PHP's common coding standards and naming conventions. See tutorial.
You can't (don't want to) install PECL extension that has latest stable version in 2014. BunnyPHP isn't as such marked as stable yet. But it is already being used in production.
- You have both classic CLI/FPM and ReactPHP applications and need to connect to RabbitMQ. BunnyPHP comes with both synchronous and asynchronous clients with same PHP-idiomatic interface. Async client uses react/promise.
Benchmarks were run as:
|Library||N (# messages)||Produce sec||Produce msg/sec||Consume sec||Consume msg/sec|
When instantiating the BunnyPHP
Client accepts an array with connection options:
Connecting with SSL/TLS
Options for SSL-connections should be specified as array
For options description - please see SSL context options.
Note: invalid SSL configuration will cause connection failure.
See also common configuration variants.
Publish a message
Now that we have a connection with the server we need to create a channel and declare a queue to communicate over before we can publish a message, or subscribe to a queue for that matter.
With a communication channel set up, we can now publish a message to the queue:
Subscribing to a queue
Subscribing to a queue can be done in two ways. The first way will run indefinitely:
The other way lets you run the client for a specific amount of time consuming the queue before it stops:
Pop a single message from a queue
A way to control how many messages are prefetched by BunnyPHP when consuming a queue is by using the channel's QOS method. In the example below only 5 messages will be prefetched. Combined with acknowledging messages this turns into an effective flow control for your applications, especially asynchronous applications. No new messages will be fetched unless one has been acknowledged.
Bunny supports both synchronous and asynchronous usage utilizing ReactPHP. The following example shows setting up a client and consuming a queue indefinitely.
There is amqp interop compatible wrapper(s) for the bunny library.
You need access to a RabbitMQ instance to run the test suite. You can either connect to an existing instance or use the provided Docker Compose setup to create an isolated environment, including a RabbitMQ container, to run the test suite in.
phpunit.xmlto fit your environment. Then run:
Use Docker Compose to create a network with a RabbitMQ container and a PHP container to run the tests in. The project directory will be mounted into the PHP container.
To test against different SSL configurations (as in CI builds), you can set environment variable
docker psto display the running containers.
Enter the PHP container.
- Within the container, run:
Large part of the PHP code (almost everything in
Bunny\Protocolnamespace) is generated from spec in file
spec/amqp-rabbitmq-0.9.1.json. Look for
DO NOT EDIT!in doc comments.
To change generated files change
Works well with RabbitMQ
Does not work with ActiveMQ because it requires AMQP 1.0 which is a completely different protocol (Bunny is implementing AMQP 0.9.1)
BunnyPHP is licensed under MIT license. See