[php-src] PR #25765: Fix GH-25763: stream_select() with a zero timeout sleeps on Windows
| From: | TonnyJe | Date: | Wed, 25 Nov 2026 22:08:07 +0000 |
| Subject: | [php-src] PR #25765: Fix GH-25763: stream_select() with a zero timeout sleeps on Windows | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41024@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25765
Author: TonnyJe
Since 8.5, stream_select() works for pipes on Windows (GH-16889, GH-17174). If no pipe is ready,
php_select() calls usleep(100) before it checks the deadline. It does that for a zero timeout too,
so polling an empty pipe takes about 15 ms.
```php
$process = proc_open([PHP_BINARY, '-n', '-r', 'fgets(STDIN);'],
[['pipe', 'r'], ['pipe', 'w']], $pipes);
$start = microtime(true);
for ($i = 0; $i < 100; $i++) {
$read = [$pipes[1]];
$write = $except = null;
stream_select($read, $write, $except, 0, 0);
}
printf("%.3f ms per call\n", (microtime(true) - $start) * 10);
fclose($pipes[0]);
```
Time per call, x64, default timer resolution:
| | before | after |
|---|---|---|
| PHP-8.5 NTS | 14.959 ms | 0.007 ms |
| PHP-8.5 ZTS | 14.995 ms | 0.007 ms |
| master NTS | 14.964 ms | 0.006 ms |
The sleep is now skipped when the timeout is exactly zero. Timeouts below 1 ms still sleep, so such
loops don't start to spin. A loop with a zero timeout now uses the CPU, as on Linux.
8.4 is not affected, it has no usleep() here. The condition looks different in master (has_sockets),
so merging up needs a manual edit.
Tested on one machine (Windows 11, i7-13700KF, VS 2022 for 8.5, VS 2026 for master, --disable-all
--enable-cli). The new test fails without the change and passes with it. I ran the tests in
ext/standard/tests/{streams,file,general_functions,network}, sapi/cli/tests and tests: the only
difference in failures is the new test. The remaining failures (17 on 8.5, 22 on master) are the
same with and without the change.
Not tested: 8.6, 32-bit, ARM64, the whole test suite.
Fixes GH-25763