← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Event-Driven Concurrency

concurrency Intermediate
debt(d7/e7/b7/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

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.

e7 Effort Remediation debt — work required to fix once spotted

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.

b7 Burden Structural debt — long-term weight of choosing wrong

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.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

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.

About DEBT scoring →

TL;DR

Event-driven concurrency uses a single-threaded event loop to handle many concurrent I/O operations — no threads, no locks, but requires non-blocking code throughout.

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

Event loops are slower than threads — for I/O-bound workloads they outperform thread-based servers (Node handles thousands of connections on one core). CPU-bound is different.

Why It Matters

Event-driven concurrency enables high-connection-count servers (chat, WebSocket, real-time) without the memory overhead of one-thread-per-connection.

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

✗ Vulnerable
// Blocks ReactPHP event loop:
$loop->addTimer(0.1, function() {
    $result = file_get_contents('http://slow-api.com'); // Blocks!
});
✓ Fixed
// Non-blocking with ReactPHP HTTP client:
$browser->get('http://api.com/data')->then(
    fn($response) => process($response->getBody()),
    fn($error) => logger()->error($error->getMessage())
);

Added 23 Mar 2026
Views 48
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 2 pings T 0 pings W 0 pings T 0 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 3 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 2 pings F 2 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 1 ping S
Amazonbot 15 Perplexity 11 Google 7 ChatGPT 3 Unknown AI 3 Ahrefs 2 Meta AI 1
crawler 41 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: High
⚡ Quick Fix
Use async libraries for all I/O in event loop contexts. Move CPU work to worker processes. Never use sleep() or blocking calls inside event handlers.
📦 Applies To
cli queue-worker ReactPHP Swoole
🔗 Prerequisites
🔍 Detection Hints
sleep\(|file_get_contents\(http
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: High Context: File Tests: Update

✓ schema.org compliant