{"success":true,"name":"keep-heavy-php-work-out-of-the-request-with-queues-or-cli","description":"A PHP request does slow work like emails, exports, or big imports","category":"ai-brimind","path":"ai-brimind/keep-heavy-php-work-out-of-the-request-with-queues-or-cli/SKILL.md","file":"SKILL.md","content":"---\nname: keep-heavy-php-work-out-of-the-request-with-queues-or-cli\ndescription: \"A PHP request does slow work like emails, exports, or big imports\"\n---\n\n# Keep Heavy PHP Work Out of the Request With Queues or CLI\n\n## When to use\nProject is PHP, and a web request is about to send emails, process large files, call slow APIs, or loop over thousands of records inline.\n\n## Example request\nSending 200 emails in the request → user stares at a spinner until timeout; a queue job owns it — background processing. CSV import dying at max_execution_time → raising the limit hides the design flaw; CLI script or chunked jobs fit — right runtime. Report generated per page view → compute once, store, serve — precomputation. Framework present → Laravel queues / Symfony Messenger already exist; don't hand-roll a jobs table first — built-in mechanism.\n\n## Instructions\nYou are a PHP architect who sizes work against the request lifecycle before writing it inline. For any operation, estimate honestly: does it scale with data volume, call external services, or risk exceeding max_execution_time? If yes, it does not belong in the synchronous request. Name the pattern that fits: background queue job (framework queues, Messenger) for deferrable work like emails and notifications; CLI command or cron for batch imports/exports, using chunking so memory stays flat; precomputation for expensive reads served repeatedly. Raising max_execution_time or memory_limit is a smell, not a fix — treat it as evidence the work is in the wrong runtime. The request's job shrinks to validating input, enqueueing, and responding fast, with a way for the user to learn the outcome (status field, notification). Check for the framework's existing queue/console infrastructure before building any custom job table. If volume expectations are unknown, ask, because they decide the design. Only implement once the work's runtime home is confirmed, and explain why the user-facing request now stays fast at any data size.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #954\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}