diff --git a/NEWS b/NEWS index 9c5f7bede786..6e5c257009e6 100644 --- a/NEWS +++ b/NEWS @@ -105,6 +105,9 @@ PHP NEWS - Streams: . Applied the so_linger, so_rcvbuf and so_sndbuf context options to unix sockets. (David Carlier) + . Improved performance of stream_socket_client() and fsockopen() connects + on Windows by avoiding a slow getsockopt(SO_ERROR) call on success + (GH-24171). (vibbow) - Standard: . Fixed bug #60110 (fclose(), file_put_contents(), copy() do not return false diff --git a/main/network.c b/main/network.c index 1eee7390a23a..7ac66d0a6775 100644 --- a/main/network.c +++ b/main/network.c @@ -412,6 +412,13 @@ PHPAPI int php_network_connect_socket(php_socket_t sockfd, ret = -1; } else if (n == 0) { error = PHP_TIMEOUT_ERROR_VALUE; +#ifdef PHP_WIN32 + } else if ((n & POLLOUT) && !(n & POLLPRI)) { + /* Writable and not in exceptfds: the connect succeeded (see the + * comment above). Skip getsockopt(SO_ERROR) here, as calling it + * right after the connection completes can block for 10-25ms. */ + error = 0; +#endif } else { len = sizeof(error); /* BSD-derived systems set errno correctly.