Library / SDK
php-amqplib/php-amqplib avatar
php-amqplib/php-amqplib

php-amqplib: pure PHP AMQP, and the demo folder that doubles as the tutorial

The most widely used PHP client for RabbitMQ

4,600 stars1,020 forksPHPLGPL-2.1

At a glance

What is it?
A pure PHP client for AMQP 0-9-1 that ships its own RabbitMQ demos, a toxiproxy based test environment and two documented publishing optimizations, and leaves the flush timing of a batch to the developer.
Who is it for?
Use it when you cannot install the PHP AMQP extension and want multi-host connection failover, but plan the batch flush interval and the message object reuse yourself, since the README documents the mechanism and leaves the numbers open. It is licensed LGPL-2.1, not permissive, which matters if you intend to modify it, and check the CHANGELOG.md before pinning a version because three releases are listed between 2025-02-18 and 2026-09-28.
Can I use it commercially?
Yes, with conditions. LGPL-2.1 is a weak copyleft licence: you can use it inside commercial and closed-source software, but if you distribute changes to its own files, you must publish those changes under the same licence.
Is it still maintained?
Yes. The repository last received commits 4 days ago.
What is it written in?
Mainly PHP, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • php-amqplib/php-amqplib4,600 ★ · -2
Star history
Repository2026-09-302026-11-15
php-amqplib/php-amqplib4.6k4.6k

-2 Stars in the last 46 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

LGPL-2.1, a master branch and releases spread over nineteen months

The packaging details matter before the code does. The license is LGPL-2.1 rather than one of the permissive licenses most PHP libraries use, so modifying the library itself carries obligations that depending on it does not. The default branch is master, and the homepage field points at the RabbitMQ getting started page rather than at a project site, while the API reference lives on a separate generated documentation host. Three releases are visible: v3.7.3 on 2025-02-18, v3.7.4 on 2025-11-23 and v3.7.5 on 2026-09-28, and the last push to master landed on 2026-10-21. That is a release roughly every ten months at the patch level, so a project that pins a version is pinning something that only moves a few times a year, and the changelog in the repository root is the place to look for what changed.

AMQP 0.9.1 by default pins your broker version

Since version 2.0 the library speaks AMQP 0-9-1 by default, which sets the floor on the broker: RabbitMQ 2.0 or later is required, and the README states that server upgrades usually need no application code change because the protocol changes infrequently. It asks you to run your own testing before upgrading anyway. On top of the base protocol, four RabbitMQ extensions are supported, and they cover most of what a production publisher actually needs: exchange to exchange bindings, basic nack so a consumer can reject a message, publisher confirms so the broker acknowledges a publish, and consumer cancel notify so the client learns the server cancelled its consumer. Extensions that modify existing methods, with alternate exchanges given as the example, are supported as well.

The demo folder is the tutorial the README refuses to write

Rather than writing a tutorial, the README hands you a runnable pair of scripts and defers the teaching to the official RabbitMQ tutorials. Start the consumer in one terminal, then publish from another, and the message arrives in the first window. Sending the word quit to the consumer is how it stops, which means the shutdown path is part of the demo rather than a separate example. If you want to watch the sockets used to reach the broker, there is a non blocking consumer for that. The rest of the demo folder is a catalogue of protocol features by file name: mirrored queues, exclusive queues with a fanout exchange, fanout exchanges with named queues in two variants, a signal based heartbeat sender, and basic_get for pulling single messages out of a queue instead of consuming a stream. The demo/config.php file sits alongside them, so credentials are not hard coded into each script.

bash
cd php-amqplib/demo
php amqp_consumer.php
bash
cd php-amqplib/demo
php amqp_publisher.php some text to publish
bash
php amqp_publisher.php quit

create_connection is a failover list, and AMQProxy is the pooling answer

For a cluster, the library does not manage a pool of its own. You hand create_connection an array of host entries and it tries the first, then the second if the first connection fails, returning the connection object from the first attempt that succeeded. If every attempt fails, what you get is the exception from the last one, which means a partial outage can surface as an error about one specific node rather than about the cluster as a whole. Each entry carries host, port, user, password and vhost, and the same credentials are repeated per host, so a per node vhost scheme means repeating them. Two related libraries are named in this area: enqueue/amqp-lib as an amqp interop compatible wrapper, and AMQProxy as a proxy that pools and reuses connections and channels to cut connection churn and CPU usage on the broker side. So failover is in the client, pooling is somebody else's project.

Batch publishing hands the flush decision back to you

The batching feature exists for one specific shape of workload: many messages going to the same exchange with the same routing key and the same options, with mandatory called out as an example of an option that has to match. You queue messages with batch_basic_publish, which only records them, and then publish_batch performs the actual send. When that send happens is not decided by the library. The worked example is a process that reads a file and publishes one message per line, where the interval has to be chosen by the developer depending on message size, and the README offers every fifty messages or every hundred as the kind of decision to make. There is no size based flush, no timer and no auto flush documented, so a producer that forgets the final publish_batch has messages sitting in memory rather than on the broker.

Reusing the message object skips re-encoding the properties

The second publishing optimization is about object lifetime rather than network batching. Properties are built once as an array, here a content type of text/plain and a delivery mode of AMQPMessage::DELIVERY_MODE_PERSISTENT, and passed into the message constructor alongside the body. The cost the README points at is that a fresh AMQPMessage per publish means those properties are encoded into the AMQP binary format again every single time, even though the values never change. Keeping one instance and swapping only the body avoids the repeated encoding, which is what setBody is for. The trade off is that the object is now shared mutable state, so a consumer callback or a concurrent publish path that also touches that instance has to agree on who owns the body at any moment.

The test environment routes through toxiproxy and an IPv6 network

The compose file builds a broker from the rabbitmq:3-management image with the AMQP ports 5671 and 5672 and the management ports 15671 and 15672 published, the working tree mounted at /src, and RABBITMQ_CONFIG_FILE pointed at tests/rabbitmq.conf inside that mount. Alongside it sits a toxiproxy service on 8474 and 5673 that depends on the broker, which is how the suite injects connection failures rather than waiting for a real outage. The compose file also defines a second network called ip6net with IPv6 enabled on the 2002:db8::/64 subnet, and both services join it. The Makefile passes the toxiproxy host, target and port into phpunit as environment variables, which is why those three values have overridable defaults at the top of the file.

makefile
.PHONY: test
test:
	TOXIPROXY_HOST=$(TOXIPROXY_HOST) \
	TOXIPROXY_AMQP_TARGET=$(TOXIPROXY_AMQP_TARGET) \
	TOXIPROXY_AMQP_PORT=$(TOXIPROXY_AMQP_PORT) \
		$(CURDIR)/vendor/bin/phpunit
makefile
.PHONY: docker-test-env
docker-test-env:
ifeq ($(DOCKER_FRESH),true)
	docker build --pull --no-cache --tag=php-amqplib-php:latest $(CURDIR)/docker/php
	docker compose build --no-cache --pull
	docker compose up --pull always --detach
else
	docker build --tag=php-amqplib-php:latest $(CURDIR)/docker/php
	docker compose up --detach
endif

Benchmarks, generated docs and a clean target that wipes ignored files

Four more Makefile targets round out what a contributor runs. The benchmark target publishes ten thousand messages of 1KB, consumes them, then runs a stream producer and a socket producer at a thousand each, which is the comparison between the two transports this library offers. The docs target downloads phpDocumentor 3.3.0 as a phar with wget, empties the docs directory, and regenerates the site from the PhpAmqpLib directory with the package name and title filled in, so the API reference is a generated build artifact, published at php-amqplib.github.io/php-amqplib/. The docker-test target runs the container with test.env injected, the working tree mounted at /src and your own user id, and the command inside is composer install followed by phpunit, which means the suite runs against your local tree rather than a copy. The clean target is git clean -xffd, so it removes ignored files as well as untracked ones.

Editorial conclusion

Use it when you cannot install the PHP AMQP extension and want multi-host connection failover, but plan the batch flush interval and the message object reuse yourself, since the README documents the mechanism and leaves the numbers open. It is licensed LGPL-2.1, not permissive, which matters if you intend to modify it, and check the CHANGELOG.md before pinning a version because three releases are listed between 2025-02-18 and 2026-09-28.

Frequently asked questions

What is AMQP used for?

AMQP 0-9-1 is the wire protocol this library implements in pure PHP, which is what lets a PHP process talk to RabbitMQ without the AMQP extension. On top of that base protocol it supports exchange to exchange bindings, basic nack, publisher confirms and consumer cancel notify.

Is RabbitMQ an AMQP?

RabbitMQ is the broker this library has been tested against, and AMQP 0-9-1 is the protocol it speaks by default since version 2.0, which requires RabbitMQ 2.0 or later. Server upgrades usually need no code change because the protocol rarely changes, though you are asked to test before upgrading.

Can you provide a tutorial for learning about RabbitMQ?

The README points you at the official RabbitMQ tutorials instead of repeating one, and ships a runnable start in the demo folder: amqp_consumer.php in one terminal and amqp_publisher.php in another, with the word quit sent to the consumer to stop it. The demo folder also covers mirrored queues, exclusive and named fanout queues, heartbeats and basic_get.

Official sources

  1. License: LGPL-2.1
  2. php-amqplib/php-amqplib on GitHub
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/php-amqplib-php-amqplib.svg)](https://hysenlabs.com/projects/php-amqplib-php-amqplib)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/php-amqplib-php-amqplib.svg)](https://hysenlabs.com/projects/php-amqplib-php-amqplib)

Was this useful?