laravel/octane
Laravel Octane supercharges Laravel by keeping your app in memory and serving requests via high-performance servers like FrankenPHP, RoadRunner, Swoole, and Open Swoole. Boot once, handle many requests fast for lower latency and higher throughput.
Laravel Octane is a high-performance server abstraction layer designed to replace traditional PHP-FPM/Apache/Nginx setups by leveraging event-driven servers (Swoole, RoadRunner, FrankenPHP, OpenSwoole). It aligns well with:
Key architectural benefits:
Misalignment risks:
TrustProxies) may need adjustments for async contexts.pdo_pgsql.persistent/mysql_persistent tuning.Prerequisites:
Feasibility assessment:
| Factor | Risk Level | Notes |
|---|---|---|
| Existing Infrastructure | Low-Medium | Requires server replacement (e.g., swap Nginx+PHP-FPM for RoadRunner). |
| Middleware Compatibility | Medium | Async-aware middleware (e.g., Illuminate\Pipeline) works; sync-only may fail. |
| Database Drivers | Medium | PDO persistent connections may need tuning; Eloquent queries must avoid blocking calls. |
| Third-Party Packages | High | Some packages (e.g., spatie/laravel-activitylog) may not support async. |
| Deployment Complexity | Medium | Docker/Kubernetes-friendly, but requires CI/CD adjustments for hot-reloads. |
Critical dependencies:
spiral/roadrunner and a worker pool (e.g., php-worker).frankenphp/frankenphp and HTTP/2 support.openswoole/swoole extension (not bundled with PHP).| Risk Area | Impact | Mitigation |
|---|---|---|
| Worker Memory Leaks | High | Monitor memory usage; use OCTANE_MAX_MEMORY config. |
| Async Middleware Bugs | Medium | Test with Octane::concurrently(); profile with Xdebug. |
| Server-Specific Issues | Medium | Prefer FrankenPHP for stability; Swoole may need tuning for high concurrency. |
| Hot-Reload Conflicts | Low | Exclude vendor/ from watch lists; use --no-reload in CI. |
| Vendor Lock-in | Low | Octane is Laravel-agnostic; servers (RR/FP/Swoole) are interchangeable. |
Key questions for stakeholders:
Octane replaces the LAMP stack’s PHP-FPM with a high-performance server, but requires complementary components:
| Component | Octane-Compatible Option | Notes |
|---|---|---|
| Web Server | FrankenPHP (bundled), RoadRunner, Swoole | FrankenPHP = Caddy + PHP; RR/Swoole need reverse proxy (Nginx/Traefik). |
| Reverse Proxy | Nginx, Traefik, Caddy | Required for RR/Swoole; FrankenPHP includes Caddy. |
| Task Queue | Swoole, RoadRunner, or Laravel Queues | Octane integrates with Laravel Queues via Octane::concurrently(). |
| Database | PostgreSQL/MySQL (with persistent conn tuning) | Avoid mysql_persistent; use connection pooling (PgBouncer). |
| Cache | Redis, Memcached | Shared-memory workers may need cache invalidation strategies. |
| Monitoring | Prometheus + Grafana | Octane exposes metrics (e.g., octane.workers, octane.requests). |
Recommended stack for most teams:
Client → Nginx/Traefik → RoadRunner (PHP Workers) → Laravel + Octane
or (simpler):
Client → FrankenPHP (Caddy + PHP) → Laravel + Octane
Phase 1: Proof of Concept (1–2 weeks)
composer require laravel/octane
octane:install frankenphp # or roadrunner/swoole
Octane::concurrently().OCTANE_MAX_MEMORY.Phase 2: Gradual Rollout (2–4 weeks)
Octane\Exceptions\WorkerException).OCTANE_WORKERS=auto or manual).OCTANE_OPCACHE_RELOAD=1 for dev).Phase 3: Full Cutover (1 week)
OCTANE_WATCH=public,app).Worker::terminate() events (crashes).OCTANE_QUEUE_WORKERS).| Laravel Feature | Compatibility | Notes |
|---|---|---|
| API Routes | ✅ Full | Async-ready; use Octane::concurrently() for blocking calls. |
| WebSockets | ✅ (Swoole/RR) | FrankenPHP supports HTTP/2 but not WebSockets natively. |
| Queue Workers | ✅ Full | Integrates with Laravel Queues; supports async jobs. |
| Horizon | ⚠️ Partial | May need custom worker setup for Swoole/RoadRunner. |
| Livewire | ✅ Full | Works with FrankenPHP/Swoole; test long-polling. |
| Inertia.js | ✅ Full | No changes needed. |
| Sanctum/Passport | ✅ Full | Async auth middleware works. |
| Filesystem Caching | ⚠️ Partial | Shared-memory workers may cause race conditions. |
| Database Transactions | ✅ Full | No issues, but avoid long transactions. |
| Scheduled Tasks | ⚠️ Limited | schedule:run may need custom worker setup. |
Known incompatibilities:
ob_start() orHow can I help you explore Laravel packages today?