The PHP Concurrency Model
Understand blocking I/O and where async helps.
PHP Is Synchronous by Default
Classic PHP runs one request per process, top to bottom, with blocking I/O. A file_get_contents() to a slow API freezes the entire script until the bytes arrive. The shared-nothing model (a fresh process per request, state torn down at the end) is wonderfully simple — but it means a single worker can do exactly one thing at a time. This lesson maps where that hurts and where async helps.
Blocking I/O, Measured
Watch wall-clock time dominated by waiting, not computing. Three sequential 1-second requests take ~3 seconds even though the CPU is idle the whole time.
<?php
$start = microtime(true);
foreach (['a', 'b', 'c'] as $job) {
usleep(1_000_000); // simulate a 1s blocking network call
echo "done $job\n";
}
printf("elapsed: %.2fs\n", microtime(true) - $start); // ~3.00sAll lessons in this course
- The PHP Concurrency Model
- PHP 8.1 Fibers
- Event Loops with ReactPHP
- High-Performance Servers with Swoole