Skip to content

Commit 021b5a6

Browse files
committed
Use multiple workers
1 parent 9242044 commit 021b5a6

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

plans/ENVLITE_SPECIFICATION.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ is functionally equivalent for the user — foreground server, Ctrl-C
162162
shuts it down — but the process tree shows envlite as the parent of
163163
`php -S`.
164164

165+
**Worker pool.** Before the launch (Unix or Windows), envlite calls
166+
`putenv('PHP_CLI_SERVER_WORKERS=3')` so the built-in server forks
167+
three worker processes and one slow request does not block every
168+
other one behind it. `PHP_CLI_SERVER_WORKERS` is the only knob —
169+
PHP exposes no CLI flag — and the variable was introduced in PHP
170+
7.4.0, matching envlite's preflight floor (no version gating
171+
needed). On Windows the variable is documented as unsupported and
172+
silently ignored, so setting it there is harmless. If the user has
173+
already exported `PHP_CLI_SERVER_WORKERS` in their environment,
174+
envlite leaves it alone (`getenv()` check before `putenv()`). The
175+
SQLite drop-in serializes writes through SQLite's file lock, so
176+
concurrent workers cannot corrupt `.ht.sqlite`; the worst case is a
177+
short serialization wait under contention, which is the same
178+
behavior a single worker would have produced sequentially.
179+
165180
The router is committed at `tools/local-env/router.php` alongside
166181
`envlite.php`; it is not installed into the repo, the manifest does
167182
not track it, and `clean` does not remove it. It has no inputs (the
@@ -1053,7 +1068,22 @@ explicit user assent. Users who want a fully clean slate run
10531068
login. `localhost` would also depend on `/etc/hosts` and the
10541069
system resolver; `127.0.0.1` is a literal address with no
10551070
surprises.
1056-
14. **Test DB is isolated via `DB_FILE` in the test config only.**
1071+
14. **`PHP_CLI_SERVER_WORKERS=3` on `php -S` launch.** PHP's built-in
1072+
server is single-threaded by default — one slow request (a WP
1073+
admin page, a long REST call) blocks everything behind it,
1074+
including the parallel admin-ajax calls (heartbeat, autosave) a
1075+
single page can fire. The env var is the only knob; there is no
1076+
CLI flag. Available since PHP 7.4 (matches envlite's floor, so
1077+
Phase 0 already guards this) and silently ignored on Windows where
1078+
it is documented as unsupported — setting it there is harmless,
1079+
so envlite's launch path is platform-uniform (`putenv()` before
1080+
`pcntl_exec`/`proc_open`). Three workers covers typical WP-admin
1081+
concurrency (the page request plus one or two parallel admin-ajax
1082+
calls) without meaningful memory overhead, and SQLite's file lock
1083+
serializes writes so the multi-worker model can't corrupt the DB.
1084+
A user-exported `PHP_CLI_SERVER_WORKERS` is respected (envlite
1085+
only `putenv()`s when the variable is unset).
1086+
15. **Test DB is isolated via `DB_FILE` in the test config only.**
10571087
phpunit's `tests/phpunit/includes/install.php` drops every WP
10581088
table on every run; without isolation it would wipe the dev
10591089
site Phase 8 installs. The split is one `define( 'DB_FILE',

tools/local-env/envlite.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ function envlite_pcntl_exec_available(): bool {
297297
function envlite_run_dev_server(string $repoRoot, int $port): int {
298298
$argv = envlite_dev_server_argv($repoRoot, $port);
299299

300+
// Multi-worker `php -S`. Only knob PHP exposes; PHP 7.4+ on Unix, ignored
301+
// on Windows. Don't clobber a user-exported value.
302+
if (getenv('PHP_CLI_SERVER_WORKERS') === false) {
303+
putenv('PHP_CLI_SERVER_WORKERS=3');
304+
}
305+
300306
if (PHP_OS_FAMILY !== 'Windows') {
301307
if (!function_exists('pcntl_exec')) {
302308
// Phase 0 enforces pcntl on Unix, but `serve` skips Phase 0 — so a

0 commit comments

Comments
 (0)