Memory keeps growing
A shared service that piles up data and never clears it grows with every request, until the worker crashes.
// static linter · Symfony · Laravel Octane · FrankenPHP worker mode
In worker mode, your services no longer die at the end of the request. Igor inspects every shared service in your Symfony container, or every singleton that outlives a request in an Octane worker, and spots leaking state, growing memory and calls that kill the worker, before you ship to production.
composer require --dev igor-php/igor-php
$ vendor/bin/igor-php . src/Service/CartService.php [PROJECT] [HIGH] Mutation of state 'items' in CartService::add() 18 | $this->items[] = $product; src/Service/ReportService.php [PROJECT] [HIGH] date_default_timezone_set() mutates process state 42 | date_default_timezone_set('Europe/Paris'); vendor/knp/snappy/src/.../AbstractGenerator.php [VENDOR] [INFO] Mutation of state 'binary' in setBinary() ℹ️ 71 findings in code that does not run during a request (console, kernel boot) — use --show-all to list them RECOMMENDATIONS [PROJECT] refactor to be stateless or implement ResetInterface [VENDOR] set a 'max_requests' limit in your Worker config$
01 · the problem
FrankenPHP keeps your Symfony kernel or your Laravel application in memory between requests. That is what makes it fast, and also what turns an innocent $this->items[] = … into data leaking from one user to the next.
A shared service that piles up data and never clears it grows with every request, until the worker crashes.
A date_default_timezone_set() or an ini_set() changes the behaviour of every following request handled by the same worker.
An exit() or a die() no longer ends a request: it kills the long-running process.
See it for yourself: the Leak Lab is a Symfony + FrankenPHP project running in Docker that reproduces every leak in real conditions. There is a Laravel Octane version too.
02 · what Igor detects
StateMutation
critical
A property or a static variable is modified at runtime.
$this->count++;
How to fix it: StateMutation
DetectSingletonMutation
critical
A setter or add* method is called on an injected shared service.
$this->gtm->addPush($data);
How to fix it: DetectSingletonMutation
DetectClosureStateLeak
critical
A closure capturing a variable is handed to a shared service.
addListener(…, fn () use ($x))
How to fix it: DetectClosureStateLeak
StaleDependency
critical
A persistent service keeps the Request, the container or the config of the first request.
__construct(private Request $request)
How to fix it: StaleDependency
MissingResetTag
critical
A service has a reset() or clear() but is not tagged kernel.reset: nothing calls it.
reset() { … } // no kernel.reset
How to fix it: MissingResetTag
UnsafeStateRestore
critical
Temporary state is restored outside finally: an exception leaves it in place.
$this->x = $old; // outside finally
How to fix it: UnsafeStateRestore
DoctrineFlushState
critical
A Doctrine listener only clears what it collected in postFlush, which a failed flush skips.
postFlush() { $this->pending = []; }
How to fix it: DoctrineFlushState
LocalStaticVariable
critical
A local static variable lives as long as the process.
static $cache = [];
How to fix it: LocalStaticVariable
ExecutionTerminator
critical
exit() or die() kills the long-running worker.
exit();
How to fix it: ExecutionTerminator
MagicMethodDestruct
critical
__destruct() on a shared service only runs when the worker dies.
function __destruct()
How to fix it: MagicMethodDestruct
IncompleteReset
warning
reset() exists but forgets to clear some mutated properties.
reset() { /* $count? */ }
How to fix it: IncompleteReset
ProcessStateMutation
warning
A function changes PHP's global configuration.
ini_set('memory_limit', …);
How to fix it: ProcessStateMutation
SuperglobalsUsage
warning
Direct access to $_GET, $_POST… instead of the Request object.
$_GET['id']
How to fix it: SuperglobalsUsage
Igor is strict on purpose. The Symfony bundle, the Laravel provider, readonly properties, services tagged kernel.reset or reset by an Octane listener, lazy initialisation and finally blocks that clean up state are recognised automatically to cut false positives. Code that never runs during a request (console commands, cache warmers, kernel boot) is folded into a single line.
03 · installation
composer require --dev \ igor-php/igor-php
The Go binary matching your version is downloaded automatically. Laravel Octane, the Claude Code plugin and the MCP server come with 0.11, still in beta: composer require --dev igor-php/igor-php:^0.11@beta.
// Symfony: config/bundles.php IgorPhp\IgorBundle\IgorPhpBundle::class => ['dev' => true, 'test' => true], // Laravel Octane: nothing to add
Symfony: enable the bundle, optional but recommended, so Igor reads the exact map of your container. Laravel: nothing to do, Composer registers IgorServiceProvider and Igor runs php artisan igor:dump itself.
php bin/console cache:clear # Symfony only vendor/bin/igor-php init
On Symfony, cache:clear builds the bundle's service map. Then init creates an igor.json tailored to your project.
vendor/bin/igor-php .
Exits with code 1 on any issue: ready for CI.
04 · fix
Pick the rule from Igor's report to see the faulty code and its fix. The full reference, for Symfony and Laravel, is also one command away: igor-php rule <RuleId>.
Why it is dangerous
The service is created once per worker. Every product added stays in $items for the next user, and memory never goes down.
The fix
Make the service stateless (store data in the session or the database), or implement ResetInterface so Symfony clears the property between two requests. On Laravel Octane: a scoped() binding, or a reset() called from an Octane listener.
final class CartService
{
private array $items = [];
public function add(Product $p): void
{
$this->items[] = $p;
}
}
final class CartService implements ResetInterface
{
private array $items = [];
public function add(Product $p): void
{
$this->items[] = $p;
}
public function reset(): void
{
$this->items = [];
}
}
Why it is dangerous
The tag manager is shared by every request on the worker: each push piles up and ends up in the next user's page.
The fix
If the dependency has to hold per-request data, implement ResetInterface on it. With the bundle enabled, Igor sees it is reset between requests and stops reporting the call.
public function onPage(array $data): void
{
// GoogleTagManager is a shared service
$this->gtm->addPush($data);
}
final class GoogleTagManager implements ResetInterface
{
private array $pushes = [];
public function addPush(array $data): void
{
$this->pushes[] = $data;
}
public function reset(): void
{
$this->pushes = [];
}
}
Why it is dangerous
Every request adds one more listener that captures its own $optin. Listeners pile up and older values fire for the following users.
The fix
Register the listener once, with #[AsEventListener], and read what you need from the event of the current request.
public function onRequest(RequestEvent $event): void
{
$optin = $event->getRequest()->cookies->has('optin');
$this->dispatcher->addListener('kernel.response',
function () use ($optin) { /* … */ });
}
#[AsEventListener('kernel.response')]
public function onResponse(ResponseEvent $event): void
{
$optin = $event->getRequest()->cookies->has('optin');
// …
}
Why it is dangerous
Octane builds a fresh Request, container and config for every request, but a singleton built at boot keeps the first request's copy for the whole life of the worker.
The fix
Read the value when you need it with request(), app() or config(), or pass the Request to the method that uses it.
// Singleton built when the Octane worker boots
final class LocaleResolver
{
public function __construct(private Request $request) {}
public function locale(): string
{
return $this->request->getPreferredLanguage();
}
}
final class LocaleResolver
{
public function locale(): string
{
return request()->getPreferredLanguage();
}
}
Why it is dangerous
The service knows how to clear itself, but without the kernel.reset tag Symfony's services_resetter never calls it: state piles up anyway.
The fix
Tag the service kernel.reset with the right method, or implement ResetInterface with autoconfiguration. on_invalid: ignore lets a decorator replace the service.
# config/services.yaml App\Audit\AuditLogger: ~ # AuditLogger has a clear() method, # but nothing calls it between requests
# config/services.yaml
App\Audit\AuditLogger:
tags:
- { name: kernel.reset, method: clear,
on_invalid: ignore }
Why it is dangerous
If render() throws, the restoring line never runs: the temporary locale stays for every following request on the worker.
The fix
Restore the state in a finally block (or a catch (\Throwable)), which runs even when something fails.
$previous = $this->locale; $this->locale = $locale; $html = $this->render(); // may throw $this->locale = $previous; return $html;
$previous = $this->locale;
$this->locale = $locale;
try {
return $this->render();
} finally {
$this->locale = $previous;
}
Why it is dangerous
Doctrine skips postFlush when the commit fails: the entities of the failed request stay in $pending and are processed on the next flush, for another user.
The fix
Clear the property at the start of the collecting event (onFlush, preFlush), or also in onClear, or make the listener resettable.
public function onFlush(OnFlushEventArgs $args): void
{
foreach ($this->scheduled($args) as $entity) {
$this->pending[] = $entity;
}
}
public function postFlush(): void
{
$this->publish($this->pending);
$this->pending = [];
}
public function onFlush(OnFlushEventArgs $args): void
{
// a failed flush skips postFlush: start clean
$this->pending = [];
foreach ($this->scheduled($args) as $entity) {
$this->pending[] = $entity;
}
}
Why it is dangerous
A local static variable is never freed: it grows with every distinct key the worker receives.
The fix
Use Symfony's Cache component, which handles expiration, instead of a static array.
public function rate(string $code): float
{
static $cache = [];
return $cache[$code] ??= $this->api->fetch($code);
}
public function rate(string $code): float
{
return $this->cache->get('rate_'.$code,
fn () => $this->api->fetch($code));
}
Why it is dangerous
In worker mode, exit() does not end the request: it stops the whole process, which has to restart.
The fix
Throw an HTTP exception (or abort() on Laravel): the framework turns it into a response and the worker keeps running.
if (!$user->isAdmin()) {
exit('Access denied');
}
if (!$user->isAdmin()) {
throw new AccessDeniedHttpException('Access denied');
}
Why it is dangerous
A shared service is only destroyed when the worker stops: the temporary file is never removed while the worker serves requests.
The fix
Clean up at the end of the work itself, in a finally block, instead of relying on __destruct().
final class PdfExporter
{
public function __destruct()
{
unlink($this->tmpFile);
}
}
public function export(Report $report): string
{
$tmp = tempnam(sys_get_temp_dir(), 'pdf');
try {
return $this->render($report, $tmp);
} finally {
unlink($tmp);
}
}
Why it is dangerous
You thought of ResetInterface, but reset() does not set $count back to zero: that property still leaks.
The fix
Reset every property the class mutates inside reset(). Igor checks the list for you.
public function reset(): void
{
$this->items = [];
// $count is never reset
}
public function reset(): void
{
$this->items = [];
$this->count = 0;
}
Why it is dangerous
The timezone changes for the whole process: every following request on this worker inherits Europe/Paris.
The fix
Pass the timezone explicitly to date objects, or set it once and for all in php.ini.
date_default_timezone_set('Europe/Paris');
$now = new \DateTimeImmutable();
$now = new \DateTimeImmutable(
'now',
new \DateTimeZone('Europe/Paris'),
);
Why it is dangerous
Superglobals do not necessarily reflect the current request inside a worker.
The fix
Inject the Request object into the controller and read the parameters from it (or request() on Laravel).
$id = $_GET['id'];
public function show(Request $request): Response
{
$id = $request->query->get('id');
}
Document it with the #[WorkerSafe(reason: '…')] attribute on the class, method or property, or with // @igor-ignore on a single line.
Freeze the existing debt with --generate-baseline, then clean up with --prune-baseline as you fix things.
You cannot fix it on your side: limit the damage with max_requests in the worker config, and report it to the maintainer.
05 · AI agents
Igor plugs into Claude Code and any MCP client: the agent runs the audit, sorts the findings, fixes one service at a time with the Symfony or Laravel remedy, and checks every fix before writing it.
Ask "audit my project for FrankenPHP worker mode" or run /igor:audit. Claude installs Igor if needed, handles reachable leaks first, and only accepts a finding with a written reason.
/plugin marketplace add igor-php/igor-php /plugin install igor@igor-php /igor:audit
/igor:watch on audits every PHP file Claude edits, so a leak is fixed before it lands.
igor-php mcp serves Igor over stdio to Claude Code, Cursor, VS Code / Copilot, Antigravity, Codex and any other MCP client. The project is loaded once, then every call is instant.
claude mcp add --scope project igor \ -- vendor/bin/igor-php mcp
Tools: audit_project, audit_file (even on unsaved code), explain_service, get_rule, project_info and baseline management. --read-only leaves out the tools that write.
06 · wherever you code
Live analysis as you type, gutter icons, baseline in one Alt + Enter.
See it on the MarketplaceIgor detects GitHub Actions and adds its annotations right on the pull request lines.
Sample workflowigor-php review prepares a triage prompt, or sends it to Gemini, Ollama or an OpenAI-compatible API.