php-amqplib

The most widely used pure-PHP client for RabbitMQ and the AMQP 0-9-1 messaging protocol.

Library
Composer
vv3.7.4
4,601stars
LGPL-2.1-or-later

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
57/100Fair
Development Activity4
Maintenance32
Community92
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
82/100Excellent
Architecture85
Code Quality82
Innovation80
Learning Curve75

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.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search