[php-src] PR #24172: Fix GH-24171: Slow stream_socket_client() connect on Windows
| From: | vibbow | Date: | Wed, 07 Oct 2026 07:45:20 +0000 |
| Subject: | [php-src] PR #24172: Fix GH-24171: Slow stream_socket_client() connect on Windows | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-39230@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/24172
Author: vibbow
Fixes #24171.
On Windows,
php_network_connect_socket() calls getsockopt(SO_ERROR) right
after select() reports that the non-blocking connect has completed. In that window,
mswsock's SockIsSocketConnected() can race with mswsock's own async thread
and wait on an empty internal completion port with a 10 ms timeout. As a result, a synchronous
stream_socket_client()/fsockopen() connect usually takes 10–25 ms
instead of ~0.2 ms. The issue has the full analysis.
On Windows we already poll for POLLOUT|POLLPRI, because Winsock reports a successful
non-blocking connect in writefds and a failed one in exceptfds (see the
existing comment). So when the poll result has POLLOUT and no POLLPRI, the
connect has succeeded and getsockopt(SO_ERROR) isn't needed. The failure path
(POLLPRI) is unchanged.
Tested on Windows 11 with a minimal NTS x64 build of this branch and of 8.5.11:
- Sync stream_socket_client() to a LAN host: median 13.8 ms → 0.31 ms.
- Sync stream_socket_client() on loopback: p95 22.4 ms → 0.43 ms.
- Refused and timed-out connects report the same errno, with the same timing, as before.
- Reading and writing on the resulting stream are unaffected.
No .phpt is included: the bug only shows up as latency, and a timing-based test would be flaky on
CI.
🤖 Generated with [Claude Code](https://claude.com/claude-code)