1 min read

What I learned running Octane in production for a year

Laravel Octane made our API 38% faster. It also gave us three memory leaks and one very confusing bug with a tenant that saw another tenant's settings for a few seconds.

Laptop with a dark code editor on a desk

Octane keeps your application in memory between requests. Bootstrapping happens once, which is where the speed comes from. Everything that assumes a fresh process per request is now a potential bug.

Singletons remember everything

A singleton that stores the current user, tenant or locale keeps that value for the next request on the same worker. Use scoped bindings for request state, they are flushed after each request.

php
// Leaks the first tenant into later requests
$this->app->singleton(TenantContext::class);

// Rebuilt for every request
$this->app->scoped(TenantContext::class);

Static properties are global state

Static caches in your own classes and in packages grow forever. We found them by recording the worker memory after every request and alerting when it grew for 1000 requests in a row.

Was it worth it?

Yes. p95 latency went from 190 ms to 118 ms and we run four fewer servers. But plan a week for auditing your code and your packages before you switch.