Why Traditional PHP Request Handling Is Slow
Standard PHP-FPM bootstraps your entire application framework from scratch on every single request — loading service providers, building the container, booting the framework — then throws it all away. Octane keeps your application booted in memory between requests, eliminating that repeated bootstrap cost.
Installing Octane
composer require laravel/octane
php artisan octane:install --server=swoole
Starting the Server
php artisan octane:start --workers=4 --task-workers=6
The Trade-off: Persistent State Between Requests
Because your application stays in memory, anything you’d normally expect to reset per-request — static properties, singleton bindings holding request-specific data — can leak between requests if you’re not careful:
// Dangerous under Octane: static state persists across requests
class RequestCounter
{
public static int $count = 0;
public function increment(): void
{
self::$count++; // never resets between requests!
}
}
// Safe: use Octane's request lifecycle hooks to reset state
use Laravel\Octane\Facades\Octane;
Octane::listen(RequestReceived::class, function () {
RequestCounter::$count = 0;
});
Avoiding Memory Leaks from Singletons
// Dangerous: binding a stateful service as a true singleton under Octane
$this->app->singleton(ReportBuilder::class);
// Safer: scoped bindings are reset between requests automatically
$this->app->scoped(ReportBuilder::class);
Concurrent Tasks with Octane
use Laravel\Octane\Facades\Octane;
[$users, $orders, $products] = Octane::concurrently([
fn () => User::count(),
fn () => Order::count(),
fn () => Product::count(),
]);
Octane’s task workers let you run independent operations genuinely in parallel, something standard synchronous PHP request handling can’t do.
Benchmarking the Difference
# Traditional PHP-FPM
ab -n 1000 -c 50 http://localhost/api/products
# Octane with Swoole
ab -n 1000 -c 50 http://localhost:8000/api/products
Typical gains are dramatic for lightweight endpoints (several times higher throughput) and more modest for database-bound endpoints, where the database itself becomes the bottleneck rather than PHP bootstrap time.
When Octane Isn’t Worth It
- Low-traffic internal tools where PHP-FPM’s simplicity outweighs the performance gain
- Codebases with extensive reliance on global/static state that would need significant auditing before it’s safe to run persistently
- Teams not ready to take on the operational complexity of a long-running application server
Conclusion
Octane delivers real performance gains by keeping your application warm between requests, but it fundamentally changes PHP’s request lifecycle assumptions. Audit for static and singleton state carefully before adopting it — that’s where most Octane migration bugs come from, not the framework itself.