Performance

FrankenPHP and Laravel: API performance

Worker mode removes the cost of booting Laravel from every request - and nothing more. Whether that is a lot depends on what share of your response time that cost is. It is arithmetic on your own measurements, not a benchmark from a blog.

8 min read

FrankenPHP is a PHP application server written in Go and built on Caddy. For a Laravel API one thing about it matters: worker mode, where the application boots once and stays in memory instead of starting from scratch on every request.

The question "will this speed up my API" has an answer, but not the kind people usually look for. You will not find it in somebody else's benchmark — neither the FrankenPHP documentation nor the Laravel Octane documentation publishes any performance figures. You will find it in a simple piece of arithmetic on your own measurements, and this guide is mostly about that arithmetic.

Where the gain comes from, and how far it reaches

With classic PHP-FPM, every request boots Laravel from the beginning: the autoloader, service providers, configuration, routes, the container. Then the application dies and the next request does all of it again.

In worker mode you pay that cost once, at startup. The worker stays alive and serves subsequent requests on an application that is already built. And here is the crux that decides everything:

Worker mode removes exactly the cost of booting the application and nothing beyond it. Database queries take just as long. Calls to external APIs take just as long. Serialising the response, encryption, generating JSON — unchanged. If your API mostly waits on the database, worker mode will not fix that by a single millisecond.

So the arithmetic runs like this: measure what share of your response time the bootstrap is, and that is what you have to win. Two extreme examples, to show the range:

  • An endpoint reading from cache. 25 ms bootstrap, 5 ms everything else. After moving to a worker: from 30 ms to about 5 ms, which is six times faster.
  • A reporting endpoint with a heavy query. 25 ms bootstrap, 400 ms query. After moving: from 425 ms to 400 ms, a 6% improvement, invisible to the user.

The same change, the same server, the same configuration — and two completely different conclusions. Which is why anybody quoting "X times faster" without stating their own timing profile is describing their API, not yours.

How to run it

Laravel uses FrankenPHP through the Octane package, which downloads and installs the server binary for you:

composer require laravel/octane
php artisan octane:install --server=frankenphp
php artisan octane:frankenphp

By default the server listens on port 8000, with 2019 as the admin port. Equivalently you can start it with octane:start --server=frankenphp, in which case the choice of server comes from the server key in config/octane.php.

The options that matter at startup: --workers (one per CPU core by default), --max-requests (500 by default), --https (enables HTTP/2, HTTP/3 and automatic certificates), --watch to reload on file changes, and --caddyfile if you need your own Caddy configuration.

In production the documentation recommends a process monitor such as Supervisor, and putting Octane behind Nginx or Apache — so that static files and SSL are handled by a server that specialises in them. And one thing that is easy to leave out of a deployment script:

php artisan octane:reload

Without it, the workers still running after a deployment hold the previous version of the code in memory. That is not a subtlety — it is the difference between deploying and appearing to deploy.

The price you pay: state between requests

The application stops dying after each request. Anything you leave in memory carries over to the next client. This is not a theoretical risk — it is the main cost of the change and the only reason moving to worker mode is not a one-line edit to a config file.

The Octane documentation points at specific traps. Service providers run register and boot once, at worker startup, and the same application instance is reused afterwards. Three classic mistakes follow from that:

  • The container injected into a singleton — it may not see bindings added later.
  • The request object injected into a singleton — headers, input and URL parameters will be from somebody else's request.
  • The configuration repository injected into a singleton — it will not see configuration changes between requests.

There are three remedies, worst to best: use bind instead of singleton; pass a closure, for instance fn () => Container::getInstance(); or — and this is what the documentation recommends — pass request data as method arguments instead of holding it in an object.

What stays safe: the app, request and config helpers, calling Container::getInstance(), and type-hinting the request object in controller methods and route closures. Those always return the current version.

Why this risk is larger in an API than on a website. An API is exactly where teams keep an HTTP client with a token, a tenant identifier or the logged-in customer's context in a singleton — because "it does not change during a request". In worker mode it changes between requests. A customer identifier set in stone inside a singleton is then not a performance bug, it is one customer's data leaking to another — and the kind that unit tests will not catch.

A safety valve that tells you something about the scale of the problem

Octane restarts a worker after 500 requests by default, describing it as a way to help prevent stray memory leaks. It is worth pausing on what that means: the framework ships a workaround for leaks switched on by default. This is not exotic, it is the expected state of affairs.

The practical conclusion: lowering --max-requests masks a leak at the cost of throughput rather than fixing it. If you have to go down to fifty, you have a leak to find, not a parameter to set. The classic culprit is a static array that every request appends to — it grows without end, because nothing clears it any more.

While we are here: max_execution_time in config/octane.php defaults to 30 seconds, and zero disables the limit. Changing it requires a server restart.

What FrankenPHP does not give you, and Swoole does

Octane supports FrankenPHP, Swoole, Open Swoole and RoadRunner, but not all of its features work everywhere. Four are documented as requiring Swoole:

  • concurrent tasks (Octane::concurrently, up to 1024 of them);
  • ticks and intervals — repeating work inside the server process;
  • the Octane cache, built on Swoole tables;
  • custom tables shared between workers.

If your API design rests on any of them — querying three external services in parallel within one request, say — then FrankenPHP is not the choice, and that is a functional decision rather than a performance one. Worth making before the installation, not after.

What FrankenPHP gives you instead

Three things Swoole does not offer, each of which matters for an API.

HTTPS with no separate configuration. The --https flag enables HTTP/2, HTTP/3 and automatic certificates — FrankenPHP sits on Caddy and inherits this from it.

Mercure built in. If the API has to push events to clients over SSE, the server can do it itself, without adding another service to your infrastructure.

The application as a single binary. FrankenPHP can embed the application code into a standalone executable, which turns deployment into copying one file. Two traps: the binary must be named frankenphp, and an application packaged this way needs its storage directory pointed at through LARAVEL_STORAGE_PATH.

How to measure before you rewrite your deployment

The arithmetic from the start of this guide needs two numbers, not an opinion. Take one representative endpoint — the one with the most traffic, not the most interesting one — and measure its median and 95th percentile under PHP-FPM, then the same under octane:frankenphp, on the same data.

One mistake can ruin the whole measurement. The example development setup in the Octane documentation starts the server with --workers=1 --max-requests=1. That setting deliberately disables the entire benefit — the worker dies after every request, so the bootstrap comes back. It is excellent for catching state bugs and useless for measuring performance. Use production-like values when measuring.

When it is worth it, and when it is not

Worth it if the bootstrap is a meaningful share of your response time — on light endpoints reading from cache it is often most of it — and if you have somewhere to run a process monitor and can add octane:reload to your deployment.

Not worth it if the API mostly waits on the database or on third-party services. The same effort spent on indexes, queries and caching will give you many times more and will not introduce a new class of bug. And not worth it if nobody on the team is ready to chase a fault that only shows up on the four hundredth request to the same worker — because that is precisely the fault that arrives here bundled with the performance.

The order is therefore simple, and it gets cheaper in that order: measure your timing profile first, fix the database next, and leave worker mode for the moment when the bootstrap really is what is left to cut.

Not working out?

If the problem stays, or you would rather not experiment on a live site, write to us and we will look at it. The diagnosis costs nothing.

Web applications

Other guides

Property developer websites and the draft 2027 rules

The amendment to the Developer Act and Portal DOM are not in force - they are a draft and an announcement. Even so, one decision when commissioning a website is shared by every version of them, and taken later it costs many times more.

The LiteSpeed Cache vulnerabilities

Two vulnerabilities, two products sharing a name, and two different categories of risk. In both cases applying the patch does not close the case - once because of what stayed in the cache, once because of who stayed in the system.

Filament: an admin panel for Laravel applications

The admin panel is the part of a system your customers never see and your own people spend eight hours a day in. Filament shortens the road to building one - provided you know what it does not do.

Drupal 10 reaches end of life

Drupal 10 stops receiving security fixes on 9 December 2026. If your site runs on it, you have weeks left to decide - and the cost depends mostly on which version you are starting from.

Getting started with AI in your company

Most failed AI projects do not fall over on the technology, but on the choice of process. So we start with what is countable and repetitive, not with what looks most impressive.

A slow website

A slow site is never one fault, it is the sum of several. We start by measuring, because without that optimisation is guesswork - and usually speeds up what was already fast.

An expired SSL certificate

Instead of your site, visitors get a red warning and have to click through "proceed anyway". Most of these cases are an expired certificate or a renewal that never finished.

Moving a website to new hosting

A migration goes well or badly depending on the order of the steps. The most expensive mistake is switching DNS before checking that the site works on the new server at all.

WordPress redirecting to spam sites

Visitors land on somebody else's site, and Google shows spam where your offer used to be. That is a break-in, not a fault - and cleaning the files alone will not hold.

The WordPress 500 error

HTTP 500 is the server saying something interrupted the code. On its own it tells you nothing - the whole job is getting to the log.

The WordPress white screen

Instead of your site you get blank white. It is one of the most common symptoms, and in most cases it can be defused in a quarter of an hour.