anantbhandarkar/make-it-right/mir-backend-php

Claude Code and agent skill by anantbhandarkar/make-it-right

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Make It Right (PHP runtime tier). Zend Engine / PHP 8.4–8.5 runtime reliability footguns that are shared across EVERY PHP backend framework (Laravel, Symfony, WordPress, Slim, Lumen) — distinct from the generic backend gates and from any one framework's mechanics. Covers: shared-nothing request lifecycle under PHP-FPM and why static/global state does not persist, concurrency = pm.max_children (not threads), long-running worker runtimes (FrankenPHP, Swoole, RoadRunner, Laravel Octane) and the state-bleed/memory-leak inversion they introduce, max_execution_time not counting blocked I/O, memory_limit, opcache plus the PHP 8.4 opcache.jit default flip, persistent PDO connection state, SIGTERM handling in queue workers, PHP's error/exception model in production, and runtime-level security settings (register_argc_argv, session.use_strict_mode, unserialize, parse_url/SSRF, Composer supply chain). TRIGGER when the backend runtime is PHP and the concern is the engine, the php.ini, or the process model — sits between mir-backend (generic) and the framework module. SKIP for Node/JVM/Go/Rust/.NET/Python/Ruby/BEAM runtimes (each has its own mir-backend-<runtime> tier). SKIP for Laravel library mechanics (Eloquent N+1, $fillable, Queues, Octane container bindings → mir-backend-php-laravel) and for Symfony/Doctrine library mechanics (Unit of Work, Serializer groups, Messenger, MapRequestPayload → mir-backend-php-symfony).

Install

npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-php

SKILL.md

The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-php.

/mir-backend-php · Make It Right (PHP runtime)

The middle tier. mir-backend decides what is correct (any language). The framework module (e.g. mir-backend-php-laravel) knows the library's mechanics. This tier owns what's true for all PHP backends because they run on the Zend Engine — the request lifecycle and process model that Laravel, Symfony, WordPress, and Slim all inherit.

Runtime versions, verified 13 August 2026:

BranchStatusLatestDates
8.5current stable8.5.9 (30 Jul 2026)active support to 31 Dec 2027, EOL 31 Dec 2029
8.4active support8.4.24JIT INI defaults changed in this branch
8.3security fixes only8.3.33
8.2security fixes only8.2.33security support ends Dec 2026
≤ 8.1end of life—no fixes at all; treat as a finding

Every branch gets 2 years of active support then 2 years of security-only fixes (the cycle was extended from 3 years to 4 in March 2024). PHP 8.6 is in development for late 2026.

Process model assumed: PHP-FPM (still the dominant production model). Long-running worker runtimes — FrankenPHP (adopted by the PHP Foundation in May 2025, source now under the php GitHub org), Swoole, RoadRunner, Laravel Octane, Symfony Runtime — are called out explicitly because they invert several of the default rules. Load order: mir-backend → mir-backend-php → <framework module>.

The PHP/Zend footguns AI walks into (framework-agnostic)

1. Shared-nothing per request — static/global state does NOT persist

The Zend Engine tears down every variable, object, and static property at the end of each request. Nothing in PHP process memory survives to the next request under FPM — there is no "warm" in-process store between requests.

  • AI commonly writes static $cache = [] inside a class, expecting it to persist across requests like an application-level cache. Under FPM each worker resets statics on every request — the "cache" is always empty at request start and is thrown away at request end.
  • Fix: persist data externally — opcache for compiled bytecode, APCu for small in-process per-worker caches (single worker only, not shared across workers), Redis/Memcached for truly shared data, DB for durable data. Treat the PHP process as a pure function: input → output.
  • Why AI errs: AI is trained on patterns from runtimes (Node, Python async) where module-level singletons genuinely survive across requests. That pattern is wrong in FPM-PHP.
php
// WRONG — resets to [] every request under FPM
class UserRepo {
private static array $cache = [];
public static function find(int $id): User {
if (!isset(self::$cache[$id])) {
self::$cache[$id] = DB::find($id); // never warm on next request
}
return self::$cache[$id];
}
}
// RIGHT — APCu for a single-worker hot cache, Redis for cross-worker
$user = apcu_fetch("user:$id", $found) ?: tap(DB::find($id), fn($u) => apcu_store("user:$id", $u, 60));
2. FPM worker model — concurrency = pm.max_children, not threads

PHP-FPM processes one request per worker process at a time. There are no threads handling concurrent requests within a worker — concurrency is purely the number of live FPM worker processes.

  • pm.max_children sets the ceiling. A slow DB query or a hung third-party API call ties up an entire worker for the full duration. With 20 workers and a downstream that takes 10 seconds, you saturate the pool after 20 simultaneous slow requests.
  • Fix: size pm.max_children to floor(available_RAM / per_worker_peak_RSS). Typical PHP-FPM workers use 20–100 MB each. Measure with ps aux --sort=rss. Also use pm = dynamic with sensible pm.min_spare_servers / pm.max_spare_servers to avoid cold-start churn.
  • A single blocking call (sync HTTP, slow query, filesystem wait) eats a whole worker slot. Set socket/HTTP timeouts aggressively; offload slow/durable work to queues. Never let a web worker sit blocked on a third-party service.
  • pm.max_requests recycles a worker after N requests. It bounds leaks in C extensions; it is not a substitute for fixing them.
ini
; php-fpm.conf — example sizing for a 1 GB container, ~50 MB/worker
[www]
pm = dynamic
pm.max_children = 18
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
pm.max_requests = 500
request_terminate_timeout = 60s ; wall-clock kill; see footgun 4
3. Long-running worker runtimes (FrankenPHP / Swoole / RoadRunner / Octane) flip the model

Under FrankenPHP worker mode, Swoole/OpenSwoole, RoadRunner, or Laravel Octane the PHP process is persistent — it handles many requests without dying. The shared-nothing guarantee is gone. Three failure classes emerge that do not exist under FPM.

symfony/runtime is not itself one of these: it is a bootstrap abstraction, and the process only persists when the selected runner loops over requests (FrankenPhpWorkerRunner, a RoadRunner or Swoole bridge). The default runner terminates per request like FPM. Check which runner is configured before deciding which set of rules applies.

State bleed. Static properties, container singletons, and class-level state set during request A are still set during request B. A singleton that holds $request, $user, or $tenant bleeds that data across users.

Under coroutine-enabled Swoole/OpenSwoole it is worse than staleness: requests interleave inside one worker. A coroutine yields at every I/O boundary and another request resumes on the same statics, superglobals, and singletons. Request-scoped state is then a race, not just a leftover — request A can read the tenant request B just wrote, mid-request. Anything request-, user-, tenant-, or session-scoped must live in coroutine-local context (Swoole\Coroutine::getContext()) or be passed as an argument. Never a process global.

php
// WRONG under any worker runtime — the singleton retains request 1's user
class AuthContext {
private static ?User $user = null;
public static function set(User $u): void { self::$user = $u; }
public static function get(): ?User { return self::$user; }
}
// After request 1 sets AuthContext::set($alice), request 2 sees $alice

Reset mechanism per stack (framework specifics live in the framework module):

RuntimeReset mechanism
Symfony, when the runner drives the HttpKernel request loop (FrankenPhpWorkerRunner, the maintained RoadRunner/Swoole bridges)services implementing Symfony\Contracts\Service\ResetInterface are auto-tagged kernel.reset and reset between requests. The kernel and container object instances themselves survive. A hand-rolled worker loop gets none of this — implementing ResetInterface does nothing unless something calls Kernel::reset(). Verify the bridge does, or the previous user/tenant/token stays live.
Symfony 8.1+ escape hatchFRANKENPHP_RESET_KERNEL=1 makes FrankenPhpWorkerRunner clone the application after each request instead of reusing the kernel.
Laravel OctaneOctane resets first-party framework state only. Your bindings are your problem — see mir-backend-php-laravel.
Anythinga static property, a function-level static $x, or a class-level cache is never reset by any of the above.

Superglobals are not all reset. FrankenPHP resets $_GET, $_POST, $_COOKIE, $_FILES, $_SERVER, $_REQUEST between requests. `$_ENV` is not reset — writes during request A are visible in request B on the same thread. Never store request-scoped or sensitive data in $_ENV. $_SESSION has been the subject of two separate cross-request leak advisories — see Security below.

Memory leaks. Objects appended to a static list, or an event dispatcher that is never flushed, grow the process heap without bound. GC cannot collect what a static reference holds. Set a request ceiling as a circuit-breaker and monitor per-worker RSS:

RuntimeRequest ceiling
FrankenPHPmax_requests <n> in the frankenphp Caddyfile block (marked experimental; default 0 = unlimited)
Laravel Octane--max-requests on octane:start (default 500)
PHP-FPMpm.max_requests

FrankenPHP sizing rule from its own docs: num_threads × memory_limit < available_memory. Its default is 2× CPU cores for both threads and workers, which is usually wrong for your app — measure.

  • Why AI errs: AI generates normal-looking singleton/static code that is safe under FPM but becomes a correctness bug under a worker runtime. Always ask at Gate 0: "Is this running under FrankenPHP worker mode / Octane / Swoole / RoadRunner?" If yes, audit every static and every container binding.
4. max_execution_time does NOT count blocked I/O — memory_limit is per request

Both limits are in php.ini and both kill the request with a Fatal error when exceeded. The trap is what max_execution_time actually measures.

  • `max_execution_time` (default 30) counts script execution only. Time spent inside system(), stream operations, sleep(), and database queries is not counted on Unix-like systems. A request blocked for 10 minutes on a hung DB query is never killed by max_execution_time. Windows is the exception — there it measures wall clock.
  • The wall-clock kill is `request_terminate_timeout` in the FPM pool config. If you only set max_execution_time, a hung downstream still holds the worker forever. Set both, and set the client/driver timeout too (PDO::ATTR_TIMEOUT, cURL CURLOPT_TIMEOUT, default_socket_timeout).
  • `memory_limit` (default 128M) is per request. AI-generated code that loads large result sets into arrays ($all = Model::all()) blows this on tables with millions of rows.
  • Fix: queue long tasks. Use set_time_limit(0) only in CLI/worker scripts, never in web-facing code. Stream or chunk large data sets (cursor()/chunk() in Laravel, toIterable() in Doctrine) instead of loading the full result into memory.
php
// WRONG — loads every row into memory at once
$users = User::all(); // Fatal: allowed memory size exhausted
// RIGHT — cursor yields one hydrated model at a time
User::cursor()->each(function (User $user) {
processUser($user);
});
5. opcache in production — and the PHP 8.4 JIT default flip

Without opcache, PHP parses and compiles every .php file from disk on every request. A 100-file framework bootstrap runs 100 file reads and 100 compilations per request. That overhead disappears entirely with a warm opcache.

ini
; php.ini — production
opcache.enable=1
opcache.memory_consumption=256 ; MB — size to fit your codebase's compiled output
opcache.max_accelerated_files=20000 ; must exceed the number of .php files in the project
opcache.validate_timestamps=0 ; prod only — leave at the default 1 in dev
opcache.revalidate_freq=0 ; irrelevant when validate_timestamps=0
; JIT — PHP 8.4 changed how it is turned on. Both lines are now required.
opcache.jit=tracing ; 8.4+ default is `disable`; was `tracing` before 8.4
opcache.jit_buffer_size=128M ; 8.4+ default is 64M; was 0 before 8.4

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
15
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/anantbhandarkar/make-it-right/mir-backend-php/badge)](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-php)

Something wrong with this skill or its page? Tell us.