Laravel Rust Bridge logo Laravel Rust Bridge
Pure Bridge Core · PHP 8.2–8.6 · Laravel 11 / 12 / 13 · MIT

Call Rust Crates & Laravel Rust Directly from Laravel DI

Connect independent ext-php-rs native PHP extensions and long-lived Tokio sidecar daemons — including first-party laravel-rust — without rewriting your Laravel application in Rust. src/ holds only the pure bridge core.

composer require olgunozoktas/laravel-rust-bridge

System Requirements & Prebuilt Downloads

Install the PHP bridge with Composer and download prebuilt binaries for Linux, macOS, and Windows — no Rust compiler required unless you compile custom crates from source.

What You Need on Your Machine
Use Case Required Software
PHP Bridge + Prebuilt Binaries (no compiling) PHP 8.2–8.6 (ext-json), Composer 2.x, Laravel 11 / 12 / 13. Optional: ext-gd with WebP for pure-PHP fallback.
Compile Tokio Sidecars from Source Rust 1.99+ (rustup / cargo, Edition 2024). Zero PHP headers and zero libclang needed on Linux, macOS, or Windows.
Compile Native ext-php-rs Extensions from Source Linux: Rust 1.99+, php8.x-dev, clang, libclang-dev.
macOS: Rust 1.99+, Homebrew php, Xcode Command Line Tools.
Windows: Rust nightly (abi_vectorcall) + rust-lld, LLVM (libclang.dll), PHP 8.2–8.4 NTS.
Automated GitHub Release Artifacts (Linux, macOS, Windows + SHA256SUMS.txt)
Platform Tokio Sidecars (PHP 8.2–8.6) Native ext-php-rs Extension
Linux x86_64 laravel-rust-http-sidecar-linux-x86_64
laravel-rust-async-fanout-sidecar-linux-x86_64
liblaravel_rust_image_variants-linux-x86_64-php8.{2,3,4,5}-nts.so
Linux arm64 laravel-rust-http-sidecar-linux-arm64
laravel-rust-async-fanout-sidecar-linux-arm64
liblaravel_rust_image_variants-linux-arm64-php8.{2,3,4,5}-nts.so
macOS Apple Silicon (arm64) laravel-rust-http-sidecar-macos-arm64
laravel-rust-async-fanout-sidecar-macos-arm64
liblaravel_rust_image_variants-macos-arm64-php8.{2,3,4,5}-nts.dylib
macOS Intel (x86_64) laravel-rust-http-sidecar-macos-x86_64
laravel-rust-async-fanout-sidecar-macos-x86_64
liblaravel_rust_image_variants-macos-x86_64-php8.{2,3,4,5}-nts.dylib
Windows x86_64 (NTS) laravel-rust-http-sidecar-windows-x86_64.exe
laravel-rust-async-fanout-sidecar-windows-x86_64.exe
laravel_rust_image_variants-windows-x86_64-php8.{2,3,4}-nts.dll

Two Execution Models, One Unified Laravel Bridge

Your controllers and Horizon jobs inject normal typed PHP interfaces. Under the hood, RustBridge routes each module to either an in-process native extension or an out-of-process Tokio sidecar daemon.

Laravel Rust Bridge dual-transport architecture Laravel controllers and Horizon jobs resolve typed contracts through BridgeManager into either Path A (in-process ext-php-rs extension with automatic PHP fallback) or Path B (out-of-process Tokio sidecar daemon over Unix socket or TCP with auth and circuit breaker). PHP-FPM / Horizon / CLI Worker (PHP 8.2–8.6) Standalone Tokio Sidecar Process Laravel App Controllers & Jobs RustBridge Core BridgeManager (DI) Path A: ext-php-rs In-process C FFI (~55 us) catch_unwind + PHP auto Path B: Transport SidecarManager Circuit Breaker + Idempotent-only retry laravel_rust_bridge_sidecar AuthGuard · NDJSON v1 · Tokio Pool laravel-rust =0.1.4 · SafeDnsResolver Unix / TCP

ext-php-rs Native Extension vs Tokio Sidecar

Pick the transport that fits your crate before writing code. Need both? Inject both contracts into the same Laravel controller or Horizon job.

Comparison between in-process ext-php-rs extensions and out-of-process Tokio sidecar daemons
Dimension Native Extension (ext-php-rs) Tokio Sidecar (SidecarModule)
Execution boundary Inside PHP-FPM / Horizon / CLI process Separate long-lived Rust daemon process
Call overhead ~55 µs (direct Zend C FFI, zero IPC) ~0.2–1.5 ms (persistent Unix socket 0600 or TCP NDJSON)
Best workload Synchronous CPU work on bytes/strings (WebP, Markdown, HTML, CSV, PDF, BLAKE3, Zstd) Async I/O, persistent pools, 100k concurrent tasks, gRPC, first-party laravel-rust
PHP version upgrades Compile once per target PHP minor (8.2–8.6) Zero recompilation across PHP 8.2 → 8.6
Fault & retry safety catch_unwind FFI panic guard + automatic PHP fallback (auto mode) OS process isolation + CircuitBreakerTransport + idempotent-only socket retries
Reference examples examples/image-variants examples/laravel-http, examples/async-fanout

Clean Laravel Integration Examples

Switch between the three core usage patterns: in-process native extensions, Tokio sidecar modules, and registering your own third-party Rust package without forking.

examples/image-variants — Single-decode [768, 960, 1536] WebP with auto PHP GD fallback
use Illuminate\Http\Request;
use Olgun\RustBridge\Examples\ImageVariants\Contracts\ImageVariantGenerator;

final class ScreenshotController
{
    public function store(Request $request, ImageVariantGenerator $variants)
    {
        $batch = $variants->generateWebpVariants(
            imageBytes: (string) $request->getContent(),
            widths: [768, 960, 1536],
            quality: 80,
        );

        return response()->json([
            'backend' => $batch->backend, // "native" or "php-gd"
            'sizes' => array_map(fn ($v) => [$v->width, $v->height, $v->sizeBytes], $batch->variants),
        ]);
    }
}

Measured Benchmarks (2026-12-02)

Measured uncontended on macOS arm64, PHP 8.4.24, and Rust 1.99.1 --release. Each WebP preset shows its own paired PHP GD baseline so speedup denominators stay transparent.

+55 µs ext-php-rs FFI overhead vs direct Rust (effort 2)
2.27× – 4.12× WebP speedup (2.27× effort 4; 4.12× vs Run B GD / 3.70× vs Run A GD)
100,000 jobs 1s concurrent tasks in 1.08s & 48.34 MB RSS (47.3× smaller than PHP Fibers)
8.8× less CPU PHP CPU for 200 × 100ms HTTP calls via laravel-rust 0.1.4 vs curl_multi
Three-tier WebP benchmark (1920x1080 PNG to [768, 960, 1536] WebP, 30 iterations)
Benchmark Run & Tier Mean (ms) p95 (ms) CPU / iter (ms) Comparison vs Paired Baseline
Run A: Pure PHP GD baseline (results-latest.json) 131.205 137.186 130.767 Run A baseline (effort = 4 parity)
Run A: PHP → ext-php-rs (effort = 4) 57.793 58.419 94.724 2.27× mean · 2.35× p95 · 1.38× CPU
Run B: Pure PHP GD baseline (results-effort2.json) 146.227 290.091 136.822 Run B paired baseline
Run B: PHP → ext-php-rs (effort = 2) 35.512 35.928 57.677 4.12× vs Run B GD (146.227 ms) · 3.70× vs Run A GD (131.205 ms) · +55 µs FFI delta

Verified PHP 8.2–8.6 & Laravel 11–13 Compatibility

Tested across real Linux (Debian 12 & Ubuntu 24.04) and macOS runtimes. Native ext-php-rs compiles against each PHP minor's Zend API; Tokio sidecars run unchanged across all PHP versions.

Verified PHP and Laravel compatibility matrix
PHP Version Zend API Laravel Verification
PHP 8.2.36 20220829 11, 12 Linux .so compiled & executed WebP + 72-file lint
PHP 8.3.6 20230831 11, 12 Linux .so compiled & executed WebP + 72-file lint
PHP 8.4.24 / 8.4.28 20240924 11, 12, 13 Full Pest (native + sidecars) & benchmarks
PHP 8.5.13 20250925 12, 13 Full Pest (bridge + both Tokio sidecars + GD fallback) & lint
PHP 8.6.0 20260924 Dev / future Full Pest (bridge + both Tokio sidecars + GD fallback) & lint

Documentation & Bundled AI Skill

Every architecture decision, security control, wire protocol detail, and third-party integration guide is documented in docs/.

Start Here

ext-php-rs vs Tokio Sidecar

Decision tree, sequence diagrams, workload catalog, and common pitfalls.

Plugin SDK

Build a Third-Party Package

Ship your own Laravel + Rust Composer package without forking the bridge.

Operations

Linux & macOS Build Guide

Multi-PHP compilation commands, phpenmod, PHP-FPM, and Horizon setup.

Security

Architecture & Security

SOLID plugin hierarchy, panic guards, anti-DNS-rebinding SSRF, auth, and idempotent retries.

Protocol

Sidecar NDJSON Protocol v1

Implement compatible sidecar daemons in Rust or any other language.

AI Skill

Bundled Extension Builder Skill

Agent skill with ext-php-rs and Tokio sidecar optimization references.