anantbhandarkar/make-it-right/mir-backend-php
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
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-phpSKILL.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:
| Branch | Status | Latest | Dates | |
|---|---|---|---|---|
| 8.5 | current stable | 8.5.9 (30 Jul 2026) | active support to 31 Dec 2027, EOL 31 Dec 2029 | |
| 8.4 | active support | 8.4.24 | JIT INI defaults changed in this branch | |
| 8.3 | security fixes only | 8.3.33 | ||
| 8.2 | security fixes only | 8.2.33 | security support ends Dec 2026 | |
| ≤ 8.1 | end 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.
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_childrensets 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_childrentofloor(available_RAM / per_worker_peak_RSS). Typical PHP-FPM workers use 20–100 MB each. Measure withps aux --sort=rss. Also usepm = dynamicwith sensiblepm.min_spare_servers/pm.max_spare_serversto 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_requestsrecycles a worker after N requests. It bounds leaks in C extensions; it is not a substitute for fixing them.
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.
Reset mechanism per stack (framework specifics live in the framework module):
| Runtime | Reset 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 hatch | FRANKENPHP_RESET_KERNEL=1 makes FrankenPhpWorkerRunner clone the application after each request instead of reusing the kernel. | |
| Laravel Octane | Octane resets first-party framework state only. Your bindings are your problem — see mir-backend-php-laravel. | |
| Anything | a 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:
| Runtime | Request ceiling | |
|---|---|---|
| FrankenPHP | max_requests <n> in the frankenphp Caddyfile block (marked experimental; default 0 = unlimited) | |
| Laravel Octane | --max-requests on octane:start (default 500) | |
| PHP-FPM | pm.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 bymax_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, cURLCURLOPT_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.
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.
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
- SKILL.md in the repositoryCheckingskills/mir-backend-php/SKILL.md
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
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-php)