Repository navigation
Conversation
On Windows, php_network_connect_socket() calls getsockopt(SO_ERROR) right after select() reports that the non-blocking connect completed. Inside mswsock, SockIsSocketConnected() can then race with mswsock's own async thread and wait on an internal completion port with a 10 ms timeout, so the call often blocks for 10-25 ms. Winsock reports a successful non-blocking connect in writefds and a failed one in exceptfds, and we already poll for POLLOUT|POLLPRI. So when only POLLOUT is set, the connect has succeeded and getsockopt() can be skipped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #24171.
On Windows,
php_network_connect_socket()callsgetsockopt(SO_ERROR)right afterselect()reports that the non-blocking connect has completed. In that window, mswsock'sSockIsSocketConnected()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 synchronousstream_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 inwritefdsand a failed one inexceptfds(see the existing comment). So when the poll result hasPOLLOUTand noPOLLPRI, the connect has succeeded andgetsockopt(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:
stream_socket_client()to a LAN host: median 13.8 ms → 0.31 ms.stream_socket_client()on loopback: p95 22.4 ms → 0.43 ms.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