Skip to content

Commit fb75acc

Browse files
committed
[HttpClient] Extract common parts and fix microtime(true) placement bug
1 parent 50de334 commit fb75acc

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/Symfony/Component/HttpClient/NativeHttpClient.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,12 @@ private static function dnsResolve(string $host, NativeClientState $multi, array
332332
{
333333
$flag = '' !== $host && '[' === $host[0] && ']' === $host[-1] && str_contains($host, ':') ? \FILTER_FLAG_IPV6 : \FILTER_FLAG_IPV4;
334334
$ip = \FILTER_FLAG_IPV6 === $flag ? substr($host, 1, -1) : $host;
335+
$now = microtime(true);
335336

336337
if (filter_var($ip, \FILTER_VALIDATE_IP, $flag)) {
337338
// The host is already an IP address
338339
} elseif (null === $ip = $multi->dnsCache[$host] ?? null) {
339340
$info['debug'] .= "* Hostname was NOT found in DNS cache\n";
340-
$now = microtime(true);
341341

342342
if ($ip = gethostbynamel($host)) {
343343
$ip = $ip[0];
@@ -359,12 +359,11 @@ private static function dnsResolve(string $host, NativeClientState $multi, array
359359

360360
$multi->dnsCache[$host] = $ip;
361361
$info['debug'] .= "* Added {$host}:0:{$ip} to DNS cache\n";
362-
$host = str_contains($ip, ':') ? "[$ip]" : $ip;
363362
} else {
364363
$info['debug'] .= "* Hostname was found in DNS cache\n";
365-
$host = str_contains($ip, ':') ? "[$ip]" : $ip;
366364
}
367365

366+
$host = str_contains($ip, ':') ? "[$ip]" : $ip;
368367
$info['namelookup_time'] = microtime(true) - ($info['start_time'] ?: $now);
369368
$info['primary_ip'] = $ip;
370369

0 commit comments

Comments
 (0)