@@ -340,30 +340,26 @@ private static function dnsResolve(string $host, NativeClientState $multi, array
340340 $ now = microtime (true );
341341
342342 if ($ ip = gethostbynamel ($ host )) {
343- $ multi ->dnsCache [$ host ] = $ ip = $ ip [0 ];
344- $ info ['debug ' ] .= "* Added {$ host }:0: {$ ip } to DNS cache \n" ;
345- $ host = $ ip ;
346- } elseif (\defined ('STREAM_PF_INET6 ' )) {
347- if ($ ip = dns_get_record ($ host , \DNS_AAAA )) {
348- $ multi ->dnsCache [$ host ] = $ ip = $ ip [0 ]['ipv6 ' ];
349- $ info ['debug ' ] .= "* Added {$ host }:0: {$ ip } to DNS cache \n" ;
350- $ host = "[ $ ip] " ;
351- } elseif (\extension_loaded ('sockets ' )) {
352- if (!$ addrInfo = socket_addrinfo_lookup ($ host , 0 , ['ai_socktype ' => \SOCK_STREAM , 'ai_family ' => \AF_INET6 ])) {
353- throw new TransportException (\sprintf ('Could not resolve host "%s". ' , $ host ));
354- }
355-
356- $ ip = socket_addrinfo_explain ($ addrInfo [0 ])['ai_addr ' ]['sin6_addr ' ];
357- $ host = "[ $ ip] " ;
358- } elseif ('localhost ' === $ host || 'localhost. ' === $ host ) {
359- $ ip = '::1 ' ;
360- $ host = "[ $ ip] " ;
361- } else {
343+ $ ip = $ ip [0 ];
344+ } elseif (!\defined ('STREAM_PF_INET6 ' )) {
345+ throw new TransportException (\sprintf ('Could not resolve host "%s". ' , $ host ));
346+ } elseif ($ ip = dns_get_record ($ host , \DNS_AAAA )) {
347+ $ ip = $ ip [0 ]['ipv6 ' ];
348+ } elseif (\extension_loaded ('sockets ' )) {
349+ if (!$ addrInfo = socket_addrinfo_lookup ($ host , 0 , ['ai_socktype ' => \SOCK_STREAM , 'ai_family ' => \AF_INET6 ])) {
362350 throw new TransportException (\sprintf ('Could not resolve host "%s". ' , $ host ));
363351 }
352+
353+ $ ip = socket_addrinfo_explain ($ addrInfo [0 ])['ai_addr ' ]['sin6_addr ' ];
354+ } elseif ('localhost ' === $ host || 'localhost. ' === $ host ) {
355+ $ ip = '::1 ' ;
364356 } else {
365357 throw new TransportException (\sprintf ('Could not resolve host "%s". ' , $ host ));
366358 }
359+
360+ $ multi ->dnsCache [$ host ] = $ ip ;
361+ $ info ['debug ' ] .= "* Added {$ host }:0: {$ ip } to DNS cache \n" ;
362+ $ host = str_contains ($ ip , ': ' ) ? "[ $ ip] " : $ ip ;
367363 } else {
368364 $ info ['debug ' ] .= "* Hostname was found in DNS cache \n" ;
369365 $ host = str_contains ($ ip , ': ' ) ? "[ $ ip] " : $ ip ;
0 commit comments