php-amqplib
The most widely used pure-PHP client for RabbitMQ and the AMQP 0-9-1 messaging protocol.
Repository Health
Technical Analysis
php-amqplib is a pure-PHP implementation of the AMQP 0-9-1 protocol, giving PHP applications a battle-tested client for talking to RabbitMQ without any C extension. It handles the full messaging lifecycle: opening connections, declaring exchanges and queues, publishing messages, and consuming them with acknowledgements, all through an object-oriented API.
Maintained by the RabbitMQ team and community with over 2 million monthly installs, it supports stream, socket, and TLS connections, publisher confirms, consumer cancel notifications, heartbeats, batch publishing, and multi-host failover, making it the default choice for message-driven PHP systems.
What You Get
- A pure-PHP AMQP 0-9-1 client that runs anywhere PHP does, with no C extension to compile
- Multiple connection types including stream, socket, lazy, and TLS/SSL (AMQPStreamConnection, AMQPSSLConnection, AMQPSocketConnection)
- Full publish/consume support with acknowledgements, publisher confirms, and consumer cancel notifications
- Advanced features such as batch publishing, message truncation limits, multi-host failover, and PCNTL/signal-based heartbeats
- A large demo directory and official RabbitMQ tutorials covering real-world messaging patterns
Common Use Cases
- Publishing background jobs and events from a PHP web app onto RabbitMQ queues
- Building long-running PHP consumer workers that process tasks with acknowledgements and reconnection logic
- Implementing fanout, topic, and direct exchange routing between microservices
- Connecting to RabbitMQ clusters with multi-host failover and TLS-secured connections
Under The Hood
Architecture - The library is organized into clear layers under the PhpAmqpLib PSR-4 namespace. Connection classes (AMQPStreamConnection, AMQPSocketConnection, AMQPSSLConnection, and their lazy variants) extend AbstractConnection, which manages the AMQP handshake, frame dispatch, and channel bookkeeping. AMQPChannel (built on AbstractChannel) exposes the protocol methods for exchange/queue declaration, publishing, and consuming, while the Wire package handles low-level frame reading and binary encoding, and Message/AMQPMessage models message bodies and properties.
Tech Stack - It is written in pure PHP (targeting PHP 7.2 through 8.x), depending only on phpseclib/phpseclib for cryptography plus the ext-sockets and ext-mbstring extensions. Development tooling includes PHPUnit for testing and PHP_CodeSniffer for style enforcement, with CI running against real RabbitMQ instances via Docker.
Code Quality - The codebase carries a substantial test suite of roughly 52 test files split into tests/Unit and tests/Functional directories, the latter exercised against a live broker. Core classes such as the 1,600-line AMQPChannel are large but cohesive, error handling is expressed through a rich hierarchy of typed AMQP exceptions, and code style is enforced via phpcs.
API Design - The public API mirrors AMQP concepts directly (connections, channels, exchanges, queues, messages), which keeps it predictable for anyone familiar with the protocol. The README and an extensive demo/ directory provide runnable examples for consumers, publishers, fanout exchanges, heartbeats, and connection recovery, though the inherent verbosity of AMQP means some boilerplate is required to wire up producers and consumers.
Used by 2 apps in this directory
EspoCRM
Marketing · Ecommerce · CRM
Open-source CRM platform with metadata-driven customization, field-level permissions, and a full REST API — deploy on your own infrastructure.
wallabag
Bookmarks Archiving
Self-hosted read-it-later app that saves clean, ad-free articles from any webpage for distraction-free reading across all your devices.