Skip to content

Job: fixed crash with more than 64 jobs and slow reading of output on Windows with PHP 8.5+ - #470

Open
TonnyJe wants to merge 2 commits into
nette:masterfrom
TonnyJe:windows-select-pipes
Open

TonnyJe wants to merge 2 commits into
nette:masterfrom
TonnyJe:windows-select-pipes

Conversation

@TonnyJe

@TonnyJe TonnyJe commented Nov 25, 2026

Copy link
Copy Markdown
  • bug fix
  • BC break? no

On Windows with PHP 8.5+, two things are wrong with how Job reads output:

Now stream_select() is called once for all jobs, in chunks of 64, and isRunning() reads 8 KB from those that are ready. A closed pipe is left out, because it would be always ready. If stream_select() fails, the job polls for itself as before. -j 1 waits the same way. Other platforms and PHP < 8.5 are not changed.

PHP 8.5.13, Windows 11, -j 8, median of 10 runs:

before after
60 tests of 5–1500 ms 4.33 s 3.81 s
100 trivial tests 0.81 s 0.63 s
8 tests, 4 MB of output each 6.79 s 0.27 s
8 tests, 2 MB to stdout and 2 MB to stderr 28.7 s 0.25 s

The "before" and "after" columns were measured in separate series on the same machine. The last two depend on the timer resolution: with a 1 ms timer, 8 × 4 MB takes about 0.5 s even before the change.

Known limits:

  • Some runs with large output are still slower (the worst was 1.8 s instead of 0.25 s) and -j 1 and -j 2 gain less, because a call without result still takes a tick. That can be fixed only in PHP, see Fix GH-25763: stream_select() with a zero timeout sleeps on Windows php/php-src#25765.
  • A test that writes endlessly is read faster, so it takes more memory until its time limit. There is no limit of output before or after this change.
  • Once the current master (without this change) did not finish a run of -j 16 in 180 s. I could not reproduce it (0 of 40 runs, with this change 0 of 500), so I don't know the cause.

Tests: the new ones pass on Windows 11 with PHP 8.5 and 8.6, NTS and ZTS, and are skipped where the code does not run. Without the change Job.select.phpt ends with a crash. All tests pass in the CI of my fork on Linux, macOS and Windows with PHP 8.1–8.6; on windows-latest with PHP 8.5.12 the new tests ran, not skipped. The new tests take about 20 s on Windows and 6 s on Linux. PHPStan fails as on master (DomQuery).

… Windows with PHP 8.5+

stream_select() on pipes takes a timer tick (about 15 ms) whenever nothing is
ready, even with zero timeout, and it was called for each running job. More
than 64 pipes in one call crash PHP. Now it is called once for all jobs, in
chunks of 64.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant