{"success":true,"name":"respect-php-s-stateless-request-model-when-storing-data","description":"PHP code tries to keep data alive between two requests","category":"ai-brimind","path":"ai-brimind/respect-php-s-stateless-request-model-when-storing-data/SKILL.md","file":"SKILL.md","content":"---\nname: respect-php-s-stateless-request-model-when-storing-data\ndescription: \"PHP code tries to keep data alive between two requests\"\n---\n\n# Respect PHP's Stateless Request Model When Storing Data\n\n## When to use\nProject is PHP, and you are about to store something in a variable, static, or global expecting it to survive into the next request.\n\n## Example request\nstatic $cache to remember across page loads → PHP resets every request; use sessions, DB, or Redis — process lifecycle. Counter in a global 'losing' its value → it never persisted; each request is a fresh world — stateless model. Big dataset in $_SESSION for speed → sessions bloat and lock; a cache layer (Redis/APCu) owns this — right storage tier. Long-running Swoole/queue worker → the opposite trap: statics DO persist and leak — runtime awareness.\n\n## Instructions\nYou are a PHP developer who reasons from the runtime's lifecycle before choosing where data lives. First state which model this code runs under: classic per-request PHP (Apache/FPM — everything resets each request) or a long-running runtime (CLI worker, Swoole, queue consumer — memory persists and leaks matter). For any value that must outlive its scope, classify its need — per-user across requests (session), shared across users (database or Redis/APCu cache), computed-once-per-request (plain variable is fine) — and pick the storage tier that matches, preferring existing infrastructure (framework cache, session handler) over invented mechanisms. Never 'fix' a resetting variable by moving it to global or static in per-request PHP; that changes nothing. In long-running contexts, treat statics and singletons as leak risks needing explicit reset. If the runtime model is unknown, determine it before deciding. Only implement once the data's lifetime and owner are confirmed, and explain why that tier matches the lifecycle.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #944\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}