This library is in it's early stage and need some more care before production usage.
RabbitRs is a native PHP extension implemented in Rust with
ext-php-rs. It provides a fast,
memory-safe AMQP 0-9-1 client built on top of
lapin, and is designed as a drop-in upgrade
for php-amqplib.
RabbitRs was born from running RabbitMQ at scale and fighting connection storms.
The project focuses on reusing connections, delivering predictable throughput,
and giving PHP developers the ergonomics they expect from php-amqplib while
leveraging the performance and safety of Rust.
- Zero PHP FFI โ native Zend extension compiled from Rust.
- Shared connection model โ one TCP/TLS connection per PHP worker, reused by
every
PhpClientin the same process. - Publisher confirms โ confirm mode enabled by default with blocking
confirms, plus compatibility helpers (
confirmSelect,waitForConfirms). - Manual or automatic acknowledgements โ full control over
ack/nack/reject, matchingphp-amqplibsemantics. - Consumer QoS โ manual QoS or adaptive auto-tuning that grows/shrinks the prefetch based on observed throughput.
- TLS & reconnection โ native TLS via
rustlswith configurable reconnect/backoff policies. - Full message metadata โ headers, properties, and binary payloads flow both ways without lossy conversions.
| Layer | Implementation details |
|---|---|
| PHP API | Classes generated with ext-php-rs (Goopil\RabbitRs\PhpClient, Goopil\RabbitRs\PhpChannel, โฆ). |
| Core runtime | Asynchronous orchestration with tokio, message pipelines on top of lapin. |
| Connection model | once_cell + parking_lot locks coordinate a single shared connection per process. |
| Backpressure | Adaptive QoS uses moving windows and cooldowns to resize prefetch without thundering. |
| Observability | tracing instrumentation is available when compiled with the tracing feature flag. |
- Rust 1.89+
- PHP 8.2 โ 8.5 (CLI, FPM, or Apache module)
- RabbitMQ (local or remote) for integration tests
cargo build --releaseThe compiled module is available in target/release/librabbit_rs.(so|dylib|dll)
depending on your platform.
Add the module to your php.ini (or drop a .ini in conf.d):
extension=/path/to/target/release/librabbit_rs.soVerify the load:
php -m | grep rabbit_rsA Composer plugin is provided under php/composer-plugin. It:
- Detects the current platform/architecture (
linux-gnu,linux-musl,darwin,windows+x86_64/aarch64). - Downloads the matching prebuilt binary from GitHub Releases.
- Caches the module under
vendor/rabbit-rs/ext/<platform>/php<version>. - Publishes
RabbitRs.stub.phpfor IDE autocompletion.
Minimal configuration snippet:
{
"require": {
"goopil/rabbit-rs-installer": "^0.1"
},
"extra": {
"rabbit-rs": {
"version": "0.1.0",
"download_template": "https://github.com/goopil/php-rabbit-rs/releases/download/%tag%/%file%"
}
}
}Set RABBIT_RS_VERSION=vX.Y.Z to override the release tag or
RABBIT_RS_FORCE_INSTALL=1 to force a re-download.
use Goopil\RabbitRs\PhpClient;
$client = new PhpClient([
'host' => 'localhost',
'user' => 'guest',
'password' => 'guest',
]);
$client->connect(); // idempotent
$channel = $client->openChannel();
$channel->queueDeclare('jobs', ['durable' => true]);
$channel->basicPublish('', 'jobs', new Goopil\RabbitRs\AmqpMessage('hello'));$client = new PhpClient([
'host' => 'my-rabbit',
'port' => 5671,
'user' => 'guest',
'password' => 'guest',
'ssl' => [
'cafile' => '/path/ca.pem',
'certfile' => '/path/client.pem',
'keyfile' => '/path/client.key',
],
]);
$client->connect();$client = new PhpClient([
'host' => 'cluster',
'user' => 'guest',
'password' => 'guest',
'reconnect' => [
'enabled' => true,
'max_retries' => 5,
'initial_delay_ms' => 100,
'max_delay_ms' => 5000,
'jitter' => 0.2,
],
]);
$client->connect();- Rust unit tests:
cargo test --all - PHP integration suite:
bash run-test.sh
Spins up RabbitMQ with Docker Compose, builds the extension (debug or release), and runs Pest tests fromphp/tests/. - Benchmarks:
bash run-benchmarks.sh
Launches a dedicated RabbitMQ instance, ensures benchmark dependencies are installed, and executes the comparison suite underphp/benchmarks/.
The GitHub Actions CI workflow executes formatting checks (cargo fmt),
clippy, Rust tests, and the integration suite on PHP 8.2.
Tagged releases trigger .github/workflows/release.yml, which:
- Builds Linux glibc binaries directly on Ubuntu runners.
- Builds Linux binaries directly on the GitHub-hosted runners; Docker builders were removed in favour of native builds.
- Compiles macOS (x86_64 & arm64) using
shivammathur/setup-php. - Packages artifacts via
scripts/package-extension.sh, producing.zipfiles,.inisnippets, and SHA256 sums. - Publishes everything to the GitHub Release along with an aggregated checksum manifest.
Future work includes native Linux packages (.deb, .rpm) and Windows builds.
- Single shared connection per process (no pool, no redundant connections).
- Graceful shutdown at
MSHUTDOWN(PHP-FPM, CLI, Apache). - Reconnect options (enabled, retries, delays, jitter).
- Queue/Exchange declare & bind helpers aligned with
php-amqplib. - Basic publish with confirms.
- Basic consume with callback.
-
ack/nack/rejectparity. - Surface
connection_name(host:pid) in RabbitMQ management UI. - Unit tests + Pest integration suite (connection, publish, declare, shutdown).
- Improved error propagation (always throw
PhpExceptionfor protocol errors). - Benchmark harness (publish/consume throughput & latency).
- Automated release pipeline (PHP 8.2โ8.5rc, Ubuntu/Alpine/macOS).
- Transaction support (
txSelect,txCommit,txRollback). - Return Message listener
- Improve consume performance
- Full FieldTable support (args, headers, nested arrays).
- Symmetric header propagation.
- Async iterator-based consumer API.
- Lazy channel recreation after reconnect.
- Consumer recovery with auto QoS reset.
- Configurable benchmark scenarios (message size, durability, QoS).
- Release documentation (semver policy, changelog template).
- Composer installer + IDE stubs.
- JSON convenience APIs (
basicPublishJson). - Adaptive QoS for consumers.
- Buffer reuse to cut allocations.
- Graceful SIGTERM drain strategy.
- Best-practice guide (connection reuse, channel fan-out).
- Performance reports (RabbitRs vs
php-amqplibvsbunny). - Prebuilt native packages (deb/rpm) and Windows distribution.
- Framework integrations (Laravel, Symfony, etc.).
- Multi-channel consumer.
- Fork and clone the repository.
- Install Rust & PHP build dependencies.
- Run
cargo fmt,cargo clippy, andbash run-test.shbefore submitting a PR. - Describe testing performed in the pull request template.
Bug reports and performance traces are very welcomeโproduction feedback drives our prioritisation.
RabbitRs is released under the MIT License. See LICENSE for details.