Octane makes your app faster by breaking the one assumption almost every Laravel package was written under: that the process starts fresh for each request and throws everything away at the end. Keep a worker alive across thousands of requests and you get a big latency win, and a new class of bug. State that used to evaporate now lingers; memory that used to be reclaimed now accumulates; a fatal error now takes down a worker that has already booted, and its replacement pays the boot cost again. Monitoring Octane is mostly about watching for the failure modes that only exist because the process stopped dying between requests.
What makes Octane monitoring different
In PHP-FPM, Laravel boots for every request and PHP frees everything when the request ends. In Octane, a worker boots once and handles thousands of requests. Three implications:
- Memory accumulates. Leaks that were invisible in PHP-FPM (PHP freed the memory after each request) now grow until max_requests recycles the worker or it crashes.
- Singletons resolved at boot carry state. A singleton resolved while the application boots (in a service provider, for example) keeps its properties across every request the worker handles. Singletons first resolved during a request are discarded when it ends. Good for perf, dangerous if you stash per-request data in the boot-time ones.
- Fatal errors restart the worker. An uncaught exception is rendered as an error response and the worker keeps serving. A PHP fatal error, such as exhausting
memory_limit, kills the worker process. Octane starts a new one, which boots the framework again.
Detecting memory leaks
Record memory at request start AND end, tagged by worker PID:
app/Http/Middleware/OctaneMemoryProbe.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class OctaneMemoryProbe
{
public function handle(Request $request, Closure $next)
{
$startMb = memory_get_usage(true) / 1024 / 1024;
$response = $next($request);
$endMb = memory_get_usage(true) / 1024 / 1024;
Log::info('Request memory', [
'pid' => getmypid(),
'route' => $request->route()?->uri(),
'start_mb' => round($startMb, 2),
'end_mb' => round($endMb, 2),
'delta_mb' => round($endMb - $startMb, 2),
]);
return $response;
}
}Filter by PID. A healthy worker's delta hovers around zero; a leaky worker's end-of-request memory creeps upward over time. When you spot a leaking worker, the most recent requests before the growth spike usually hold the culprit.
Octane-safe patterns
Don't stash per-request data in singletons
// Bad if resolved at boot: the first user sticks for the worker's lifetime
$this->app->singleton(UserContext::class, function ($app) {
return new UserContext($app['auth']->user());
});
// Good: bind fresh per request
$this->app->bind(UserContext::class, function ($app) {
return new UserContext($app['auth']->user());
});Use listeners for per-request reset
// app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Event;
use Laravel\Octane\Events\RequestTerminated;
public function boot(): void
{
Event::listen(function (RequestTerminated $event) {
// Clear anything that shouldn't carry between requests
app(MyStatefulThing::class)->reset();
});
}Driver-specific notes
FrankenPHP
Single binary. Built-in HTTPS. The simplest operational story. Worker mode shares most Octane semantics. Supports HTTP/3 which matters for latency-sensitive APIs.
Swoole
Adds Octane features the other drivers lack, such as concurrent tasks: Octane::concurrently([...]) fans out I/O-bound work to Swoole task workers. Requires the swoole PHP extension; more complex operational story than FrankenPHP.
RoadRunner
Go-based worker manager, mature and stable. It runs as a separate rr binary that Octane downloads for you, with the spiral/roadrunner-cli and spiral/roadrunner-http Composer packages alongside.
What to alert on
- Worker crashes: alert on crash rate > 0 sustained. Crashes usually mean a fatal error, such as a request exhausting
memory_limit. - Memory growth: per-worker delta trending upward over 100+ requests.
- Request latency regression: if p95 on Octane looks like PHP-FPM, something's wrong with your deploy.
- max_requests restart rate spike: if workers recycle far more often than max_requests suggests, something is OOM-killing them.
NightOwl won't raise these alerts itself: it alerts when a new exception appears or a request crosses its route's duration threshold, so the rate and trend checks above need your process supervisor or metrics stack.