// guide

Symfony and FrankenPHP worker mode: avoid memory and state leaks

Since Symfony 7.4, FrankenPHP worker mode is supported natively. The kernel stays booted between requests: Symfony clears the services tagged kernel.reset, and every other shared service keeps its state. Here is what to check before you switch.

Last updated: November 2026

Enable worker mode

Point FrankenPHP's worker at the front controller, in the Caddyfile or through FRANKENPHP_CONFIG in Docker:

php_server {
    worker ./public/index.php
}

# or, with the Docker image
-e FRANKENPHP_CONFIG="worker ./public/index.php"

Symfony 7.4 and later need nothing else. On older versions, add the runtime: composer require runtime/frankenphp-symfony and set APP_RUNTIME=Runtime\FrankenPhpSymfony\Runtime. See FrankenPHP's Symfony documentation.

What Symfony resets for you, and what it does not

Between two requests, Symfony's services_resetter calls reset() on every service tagged kernel.reset: Monolog buffers, the Doctrine registry, the framework's own caches… A service of yours that implements Symfony\Contracts\Service\ResetInterface gets the tag automatically with autoconfiguration.

Every other shared service is created once per worker. Its properties, the static properties of its class and the static variables of its methods keep what the first requests put there. That is how a cart, a tag manager or a cached user ends up in the next visitor's response.

Symfony 8.1: switch to worker mode before your app is ready

Symfony 8.1 adds an opt-in feature: define the FRANKENPHP_RESET_KERNEL environment variable where you configure your FrankenPHP workers, and the runtime clones the kernel after each request. The next one starts with a fresh kernel and container (Symfony blog announcement, symfony/symfony#64055).

FRANKENPHP_RESET_KERNEL=1

# with the Docker image
-e FRANKENPHP_RESET_KERNEL=1

Without the variable, nothing changes: the kernel is still reused across requests. With it, services that keep state without implementing ResetInterface no longer hand it to the next request. Throughput drops on a "hello world" benchmark, but stays several times faster than classic non-worker mode, with full per-request isolation.

That makes it a good first step: your app already benefits from worker mode while you make it compatible.

  1. Enable the worker with FRANKENPHP_RESET_KERNEL=1 to gain performance without risking a leak from one user to the next through container services.
  2. Audit and fix with igor-php: every shared service becomes stateless or implements ResetInterface (see the checklist below).
  3. Remove the variable once the audit is clean, to keep the kernel between requests and get the full throughput of worker mode.

The reset covers the kernel and the container, not the process: static properties and variables, ini_set(), date_default_timezone_set() or an exit() still affect the whole worker. igor-php reports those too, so keep it in CI from the first step.

The usual suspects in Symfony code

  • A property or static variable modified at runtime ($this->items[] = …).
  • A setter or add*() method called on an injected shared service.
  • A closure capturing a variable handed to a shared service (addListener(…, fn () use ($x))).
  • A service that has a reset() method but no kernel.reset tag: nothing calls it. Or a reset() that forgets some properties.
  • Temporary state, such as the locale, restored outside a finally block: an exception leaves it in place.
  • A Doctrine listener that only clears its state in postFlush, which a failed flush skips.
  • exit(), die(), __destruct() on a shared service, ini_set(), date_default_timezone_set() and direct access to superglobals.

These are the thirteen rules igor-php checks, each with a fix example.

Checklist before switching

  1. Audit the code with igor-php, the bundle enabled so it reads the exact map of your container. It is the tool presented in the official FrankenPHP documentation, under Auditing worker compatibility. Then:
    composer require --dev igor-php/igor-php
    php bin/console cache:clear
    vendor/bin/igor-php init
    vendor/bin/igor-php .
  2. Fix each finding: stateless service or ResetInterface. Document a false positive with #[WorkerSafe(reason: '…')], freeze legacy debt with --generate-baseline.
  3. Optionally, prove it at runtime with Igor Doctor, still experimental: bin/console igor:worker-scan replays every route on one booted kernel, logs users in, submits the forms in rolled-back transactions and reports what a request leaves for the next one.
  4. Keep Igor in CI: it exits with code 1 on any issue and annotates pull requests on GitHub Actions.
  5. Set a safety net: restart workers after a number of requests, keep max_threads × memory_limit below the available memory, and monitor memory after the deploy, see below (and the memory leak guide for a per-route listener).

After the deploy: monitor resources (strongly recommended)

A static audit does not replace watching production. After switching to worker mode, monitor the resources of the server and of each worker, at least for the first days and after every deploy. The signal to look for is simple: memory that only goes up, request after request, instead of levelling off after warm-up. Other signs: workers that restart or crash, a queue that grows, response times that drift.

  • Ember, recommended by FrankenPHP, is a terminal dashboard for Caddy and FrankenPHP: per-thread state, worker queue and crashes, memory per request and per route. It reads Caddy's admin API (keep it on localhost:2019, never public) and needs the metrics global option. Run ember on the server, or ember --daemon --expose :9191 to export Prometheus metrics.
  • Container or server memory over time: docker stats for a quick look, your host's dashboard, or Prometheus and Grafana with an alert when memory keeps climbing over several hours.
  • Memory per route in your logs, with the kernel.terminate listener that logs memory after each request: it tells you which route makes memory grow.

When memory climbs: note the routes involved, run vendor/bin/igor-php . on the code deployed, and keep worker restarts as a safety net until the leak is fixed.

Found in the wild

  • Symfony 7.4: stateful validators keep the last submitted form and its author between requests, fixed upstream in Symfony 8.1 (symfony/symfony#63945).
  • API Platform: a worker-mode leak, now the published advisory GHSA-xmq6-3c6q-fr8m, reproduced by Igor Doctor on the official demo in one scan.

Igor Doctor is an experimental proof of concept built for the Symfony AI & MCP Hackathon (90-second demo).

Frequently asked questions

Does Symfony support FrankenPHP worker mode natively?
Yes, since Symfony 7.4. For older versions, install the runtime/frankenphp-symfony package and set APP_RUNTIME=Runtime\FrankenPhpSymfony\Runtime.
Which Symfony services are reset between requests in worker mode?
Only the services tagged kernel.reset: the services_resetter calls their reset method between two requests. A service implementing ResetInterface gets the tag through autoconfiguration. Any other shared service keeps its properties for the whole life of the worker.
Can I use worker mode before my app is ready?
Yes, with Symfony 8.1: set FRANKENPHP_RESET_KERNEL=1 and the runtime starts each request from a fresh kernel and container. Slower than the full worker, but several times faster than classic mode. Then audit with igor-php, fix, and remove the variable. Static and global state (ini_set(), timezone, exit()) still needs fixing.
Do I need to call $entityManager->clear() in worker mode?
Not between requests: DoctrineBundle resets the entity manager. You still need it inside long requests and batches that load many entities, or the memory peak happens within that single request.
How do I check a Symfony app before enabling worker mode?
Run igor-php: composer require --dev igor-php/igor-php, enable its bundle in dev and test, run php bin/console cache:clear, vendor/bin/igor-php init and vendor/bin/igor-php .. It exits with code 1 on any issue, so it fits in CI. Igor Doctor, an experimental hackathon project, can then replay your routes at runtime.
Can vendor bundles leak too?
Yes. Igor audits vendor/ and bundles too. Igor Doctor, an experimental runtime probe, found stateful validators in Symfony 7.4 (fixed in 8.1) and reproduced the API Platform advisory GHSA-xmq6-3c6q-fr8m on the official demo.