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.
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.
| 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. |
| Platform | Tokio Sidecars (PHP 8.2–8.6) | Native ext-php-rs Extension |
|---|---|---|
Linux x86_64 |
laravel-rust-http-sidecar-linux-x86_64laravel-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-arm64laravel-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-arm64laravel-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_64laravel-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.exelaravel-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.
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.
| 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.
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),
]);
}
}
use Olgun\RustBridge\Examples\LaravelHttp\Contracts\ConcurrentHttpClient;
use Olgun\RustBridge\Examples\LaravelHttp\Data\HttpBatchRequest;
final class CatalogAggregator
{
public function __construct(private ConcurrentHttpClient $http) {}
public function fetchDashboard(): array
{
$batch = $this->http->sendBatch([
HttpBatchRequest::get('catalog', 'https://internal.service/catalog'),
HttpBatchRequest::get('pricing', 'https://internal.service/pricing'),
HttpBatchRequest::postJson('audit', 'https://internal.service/events', ['type' => 'view']),
], maxConcurrency: 8);
return [
'laravel_rust_version' => $batch->crateVersion, // "0.1.4"
'catalog' => $batch->get('catalog')?->json(),
'pricing' => $batch->get('pricing')?->json(),
];
}
}
use Illuminate\Contracts\Foundation\Application;
use Olgun\RustBridge\Data\NativeExtensionSpec;
use Olgun\RustBridge\Facades\RustBridge;
use Olgun\RustBridge\Modules\NativeModuleDefinition;
use Olgun\RustBridge\Native\NativeExtensionDetector;
RustBridge::registerNativeModule(new NativeModuleDefinition(
name: 'acme-markdown',
extension: NativeExtensionSpec::forExtension(
extensionName: 'acme_markdown',
expectedAbiVersion: 1,
requiredFunctions: ['acme_markdown_to_html'],
),
nativeFactory: fn (Application $app, NativeExtensionDetector $detector) => new NativeMarkdownRenderer($detector),
fallbackFactory: fn (Application $app) => new PhpMarkdownRenderer(),
contract: MarkdownRenderer::class,
package: 'acme/laravel-rust-markdown',
));
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.
| 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.
| 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/.
ext-php-rs vs Tokio Sidecar
Decision tree, sequence diagrams, workload catalog, and common pitfalls.
Build a Third-Party Package
Ship your own Laravel + Rust Composer package without forking the bridge.
Linux & macOS Build Guide
Multi-PHP compilation commands, phpenmod, PHP-FPM, and Horizon setup.
Architecture & Security
SOLID plugin hierarchy, panic guards, anti-DNS-rebinding SSRF, auth, and idempotent retries.
Sidecar NDJSON Protocol v1
Implement compatible sidecar daemons in Rust or any other language.
Bundled Extension Builder Skill
Agent skill with ext-php-rs and Tokio sidecar optimization references.
More Products by the Same Author
Other production web applications and developer tools maintained by Olgun Ozoktas: