Soft launch: this site is a work in progress.
Raphael BADA
Raphael BADAApp Developer
Back to articles

Laravel Octane: Supercharging Your API Performance

How to serve thousands of requests per second with Swoole, RoadRunner, and Laravel Octane — with benchmarks and real-world configuration tips.

Raphael BADA
Feb 17, 20268 min
Laravel Octane: Supercharging Your API Performance

Introduction

Traditional PHP applications have a fundamental performance limitation: every request boots the entire framework from scratch. Laravel Octane changes this by keeping your application in memory between requests, resulting in 10-20x performance improvements for typical API workloads.

In this guide, we'll set up Octane, benchmark it against a standard Laravel setup, and cover the gotchas you need to know for production deployment.

How Octane Works

Octane uses high-performance application servers — Swoole or RoadRunner — to boot your Laravel application once and keep it in memory. Subsequent requests skip the bootstrap phase entirely:

  • Without Octane: Boot framework → Load config → Register providers → Handle request → Shutdown (every single request)
  • With Octane: Boot framework once → Handle request 1 → Handle request 2 → Handle request N... (framework stays warm)
Think of it like the difference between starting your car engine for every trip versus keeping it running. Octane keeps the engine warm.

Setting Up Octane

Installation is straightforward:

composer require laravel/octane
php artisan octane:install

You'll be asked to choose between Swoole and RoadRunner:

  • Swoole — PHP extension written in C. Higher performance ceiling, but requires installing the extension. Best for maximum throughput.
  • RoadRunner — Go-based server. Easier setup (no PHP extension needed), slightly lower peak performance. Best for simpler deployments.

Start the server:

php artisan octane:start --server=swoole --port=8000 --workers=4

Real-World Benchmarks

We benchmarked a typical JSON API endpoint (database query + JSON serialization) using Apache Bench with 100 concurrent connections:

  • Standard Laravel (PHP-FPM): ~380 requests/second
  • Laravel + RoadRunner: ~2,800 requests/second (7.4x improvement)
  • Laravel + Swoole: ~4,200 requests/second (11x improvement)

For a complex API with multiple Eloquent queries, JSON Resources, and middleware:

  • Standard Laravel: ~120 requests/second
  • Laravel + Swoole: ~1,800 requests/second (15x improvement)

The more complex your request lifecycle, the more Octane helps — because the framework boot time represents a larger percentage of total request time.

Concurrent Tasks

Octane enables true concurrency within a single request. Need to call three external APIs? Run them simultaneously:

use Laravel\Octane\Facades\Octane;

[$users, $orders, $analytics] = Octane::concurrently([
    fn () => Http::get('https://api.example.com/users'),
    fn () => Http::get('https://api.example.com/orders'),
    fn () => Http::get('https://api.example.com/analytics'),
]);

This reduces a 3-second sequential workflow (3 × 1s API calls) to just 1 second.

Production Gotchas

Octane introduces state persistence between requests, which requires careful coding:

  • Static properties persist — never store request-specific data in static variables. Use request or container bindings instead.
  • Singleton services persist — services resolved as singletons live across requests. Make sure they don't hold user-specific state.
  • File handles stay open — if you open files or database connections, they persist. Use proper cleanup in terminated listeners.
  • Memory leaks — monitor memory usage closely. A leak that adds 1KB per request becomes 1GB after a million requests.
// octane.php config - flush these between requests
'flush' => [
    'auth',
    'cache',
    'session',
],

Deployment Tips

  • Use a process manager like Supervisor to restart workers if they crash
  • Set --max-requests=1000 to periodically restart workers and prevent memory leaks
  • Put Nginx in front of Octane for SSL termination, static file serving, and load balancing
  • Monitor with Laravel Horizon for queue workers and Laravel Telescope for request debugging

Conclusion

Laravel Octane is a game-changer for API-heavy applications. With minimal code changes, you can achieve performance numbers that previously required switching to Node.js or Go. The key is understanding the state persistence model and coding defensively against memory leaks. For any Laravel API serving more than a few hundred requests per second, Octane should be your first optimization — before caching, before horizontal scaling, before anything else.

#Performance #Laravel
Share this article
Written by

Raphael BADA

A developer passionate about Flutter, Laravel, and modern design — sharing hands-on insights through technical articles and practical tutorials.

Contact Me

Have a project in mind? Let's talk.

Send me a message

© 2026 Raphael BADA. All rights reserved.