Worker Pool Patterns
debt(d7/e5/b7/t7)
Closest to 'only careful code review or runtime testing' (d7). The detection_hints list php-fpm-status, datadog, and prometheus — all operational/monitoring tools that only surface problems (OOM kills, cold-start latency, saturated worker queues) after the system is under real load. A misconfigured pm.max_children or the absence of a pool pattern produces no compile-time or lint-time signal; misuse is silent until traffic reveals it.
Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix points to tuning PHP-FPM config (pm.max_children, pm mode), which sounds like a one-liner, but common_mistakes show multiple independent failure modes — pool sizing, backpressure, crash-restart logic, and shared-state elimination. Addressing all of them typically means changes to FPM pool config, queue/job infrastructure, and worker lifecycle management across several configuration and code files.
Closest to 'strong gravitational pull' (b7). applies_to covers both web and CLI contexts, meaning the pool configuration shapes how the entire PHP runtime handles concurrency. Every background job, every burst-traffic spike, every memory budget decision is constrained by the pool sizing choice. Misconfigurations (pool too large, wrong pm mode) persistently affect throughput and stability across all work streams, and correcting them requires revisiting infrastructure and application design together.
Closest to 'serious trap — contradicts how a similar concept works elsewhere' (t7). The misconception field states explicitly: developers assume spawning a new process per task is equivalent to a pool, but process spawning costs 10-100ms versus <1ms for a pre-spawned worker. This contradicts intuition from thread-pooling in JVM/Go ecosystems where thread creation is cheap, and leads developers to build architectures that silently waste tens of seconds of overhead at scale before the error becomes obvious.
Also Known As
TL;DR
Explanation
A worker pool maintains N pre-spawned workers ready to accept tasks. Benefits: no per-task spawn overhead (50ms each), bounded resource usage, backpressure. PHP implementations: amphp/parallel for process pools, Laravel Horizon for queue workers.
Common Misconception
Why It Matters
Common Mistakes
- Pool larger than CPU cores for CPU-bound work
- No backpressure
- Not restarting crashed workers
- Shared mutable state between workers
Code Examples
foreach ($images as $img) { $p = new Process(['php','resize.php',$img]); $p->start(); }
$pool = new DefaultPool(8);
$promises = array_map(fn($img) => $pool->enqueue(new CallableTask('resize',[$img])), $images);
await Promise\all($promises);