Event-Driven Concurrency
debt(d7/e7/b7/t7)
Closest to 'only careful code review or runtime testing' (d7). The detection_hints note automated=no, with only basic code_pattern hints (sleep\(|file_get_contents\(http). There is no tooling that comprehensively catches all blocking calls (e.g., sync PDO, CPU-bound loops) inside an event loop — most violations are invisible at rest and only manifest as latency/throughput degradation under load, requiring runtime testing or careful review to discover.
Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix says 'Use async libraries for all I/O in event loop contexts' and common_mistakes include using sync PHP libraries (PDO) everywhere. Replacing synchronous DB drivers, HTTP clients, and file I/O with async equivalents (ReactPHP MySQL, Swoole PDO, async HTTP) touches every I/O call across the codebase — this is a pervasive, cross-cutting change, not a single-file fix.
Closest to 'strong gravitational pull' (b7). The choice to adopt event-driven concurrency shapes every I/O interaction in the affected contexts (cli, queue-worker). Every future library addition must be evaluated for async compatibility, every DB call must use async drivers, and every CPU-bound task must be offloaded. This is a persistent, system-wide constraint that every maintainer must internalize.
Closest to 'serious trap' (t7). The misconception field explicitly states the common wrong belief (event loops are slower than threads), but the deeper operational trap from common_mistakes is that developers naturally reach for familiar sync libraries (PDO, file_get_contents) inside event loops — blocking all coroutines silently — which contradicts how synchronous code behaves correctly in non-event-loop contexts. This contradicts expectations from thread-based or synchronous PHP programming patterns.
TL;DR
Explanation
Event loop: waits for I/O events (network, file, timer), dispatches callbacks. Node.js, ReactPHP, Swoole use this model. Benefits: no race conditions on shared state (single thread), low memory (no thread stacks), high I/O throughput. Limitation: CPU-bound code blocks the event loop for all other connections. The golden rule: never block the event loop — use async I/O everywhere. PHP: ReactPHP (promises), Swoole (coroutines with implicit yield), Revolt (fibers). Breaking the rule: sleep(), blocking DB query, CPU-heavy computation in the event handler.
Common Misconception
Why It Matters
Common Mistakes
- Blocking the event loop with synchronous I/O or CPU work.
- Using sync PHP libraries (PDO) in an async event loop — blocks all other coroutines.
- Not switching to async DB drivers (ReactPHP MySQL, Swoole PDO) when using event loops.
Code Examples
// Blocks ReactPHP event loop:
$loop->addTimer(0.1, function() {
$result = file_get_contents('http://slow-api.com'); // Blocks!
});
// Non-blocking with ReactPHP HTTP client:
$browser->get('http://api.com/data')->then(
fn($response) => process($response->getBody()),
fn($error) => logger()->error($error->getMessage())
);