8000 bug #32147 [HttpClient] fix timing measurements with NativeHttpClient… · symfony/symfony@a590829 · GitHub
[go: up one dir, main page]

Skip to content

Commit a590829

Browse files
committed
bug #32147 [HttpClient] fix timing measurements with NativeHttpClient (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] fix timing measurements with NativeHttpClient | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Align to what curl does. Commits ------- c5c3332 [HttpClient] fix timing measurements with NativeHttpClient
2 parents e8c68d5 + c5c3332 commit a590829

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/Symfony/Component/HttpClient/NativeHttpClient.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ public function request(string $method, string $url, array $options = []): Respo
9898
'http_code' => 0,
9999
'redirect_count' => 0,
100100
'start_time' => 0.0,
101-
'fopen_time' => 0.0,
102101
'connect_time' => 0.0,
103102
'redirect_time' => 0.0,
103+
'pretransfer_time' => 0.0,
104104
'starttransfer_time' => 0.0,
105105
'total_time' => 0.0,
106106
'namelookup_time' => 0.0,
@@ -118,7 +118,7 @@ public function request(string $method, string $url, array $options = []): Respo
118118
$onProgress = static function (...$progress) use ($onProgress, &$lastProgress, &$info) {
119119
$progressInfo = $info;
120120
$progressInfo['url'] = implode('', $info['url']);
121-
unset($progressInfo['fopen_time'], $progressInfo['size_body']);
121+
unset($progressInfo['size_body']);
122122

123123
if ($progress && -1 === $progress[0]) {
124124
// Response completed
@@ -133,14 +133,14 @@ public function request(string $method, string $url, array $options = []): Respo
133133

134134
// Always register a notification callback to compute live stats about the response
135135
$notification = static function (int $code, int $severity, ?string $msg, int $msgCode, int $dlNow, int $dlSize) use ($onProgress, &$info) {
136-
$now = microtime(true);
137-
$info['total_time'] = $now - $info['start_time'];
136+
$info['total_time'] = microtime(true) - $info['start_time'];
138137

139138
if (STREAM_NOTIFY_PROGRESS === $code) {
139+
$info['starttransfer_time'] = $info['starttransfer_time'] ?: $info['total_time'];
140140
$info['size_upload'] += $dlNow ? 0 : $info['size_body'];
141141
$info['size_download'] = $dlNow;
142142
} elseif (STREAM_NOTIFY_CONNECT === $code) {
143-
$info['connect_time'] += $now - $info['fopen_time'];
143+
$info['connect_time'] = $info['total_time'];
144144
$info['debug'] .= $info['request_header'];
145145
unset($info['request_header']);
146146
} else {
@@ -310,7 +310,7 @@ private static function dnsResolve(array $url, NativeClientState $multi, array &
310310
throw new TransportException(sprintf('Could not resolve host "%s".', $host));
311311
}
312312

313-
$info['namelookup_time'] += microtime(true) - $now;
313+
$info['namelookup_time'] = microtime(true) - ($info['< 10000 span class="pl-s x">start_time'] ?: $now);
314314
$multi->dnsCache[$host] = $ip = $ip[0];
315315
$info['debug'] .= "* Added {$host}:0:{$ip} to DNS cache\n";
316316
} else {
@@ -368,10 +368,9 @@ private static function createRedirectResolver(array $options, string $host, ?ar
368368
return null;
369369
}
370370

371-
$now = microtime(true);
372371
$info['url'] = $url;
373372
++$info['redirect_count'];
374-
$info['redirect_time'] = $now - $info['start_time'];
373+
$info['redirect_time'] = microtime(true) - $info['start_time'];
375374

376375
// Do like curl and browsers: turn POST to GET on 301, 302 and 303
377376
if (\in_array($info['http_code'], [301, 302, 303], true)) {

src/Symfony/Component/HttpClient/Response/NativeResponse.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getInfo(string $type = null)
8080

8181
$info = $this->info;
8282
$info['url'] = implode('', $info['url']);
83-
unset($info['fopen_time'], $info['size_body'], $info['request_header']);
83+
unset($info['size_body'], $info['request_header']);
8484

8585
if (null === $this->buffer) {
8686
$this->finalInfo = $info;
@@ -128,7 +128,6 @@ private function open(): void
128128
$this->info['request_header'] .= implode("\r\n", $context['http']['header'])."\r\n\r\n";
129129

130130
// Send request and follow redirects when needed
131-
$this->info['fopen_time'] = microtime(true);
132131
$this->handle = $h = fopen($url, 'r', false, $this->context);
133132
self::addResponseHeaders($http_response_header, $this->info, $this->headers, $this->info['debug']);
134133
$url = ($this->resolveRedirect)($this->multi, $this->headers['location'][0] ?? null, $this->context);
@@ -146,7 +145,7 @@ private function open(): void
146145

147146
return;
148147
} finally {
149-
$this->info['starttransfer_time'] = $this->info['total_time'] = microtime(true) - $this->info['start_time'];
148+
$this->info['pretransfer_time'] = $this->info['total_time'] = microtime(true) - $this->info['start_time'];
150149
restore_error_handler();
151150
}
152151

@@ -267,6 +266,7 @@ private static function perform(NativeClientState $multi, array &$responses = nu
267266
if (null !== $e || !$remaining || feof($h)) {
268267
// Stream completed
269268
$info['total_time'] = microtime(true) - $info['start_time'];
269+
$info['starttransfer_time'] = $info['starttransfer_time'] ?: $info['total_time'];
270270

271271
if ($onProgress) {
272272
try {

0 commit comments

Comments
 (0)
0