Skip to content
Permalink
Browse files

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
  • Loading branch information...
fabpot committed Jun 26, 2019
2 parents e8c68d5 + c5c3332 commit a59082937f45e251b3516aee9046c232cacffb17
@@ -98,9 +98,9 @@ public function request(string $method, string $url, array $options = []): Respo
'http_code' => 0,
'redirect_count' => 0,
'start_time' => 0.0,
'fopen_time' => 0.0,
'connect_time' => 0.0,
'redirect_time' => 0.0,
'pretransfer_time' => 0.0,
'starttransfer_time' => 0.0,
'total_time' => 0.0,
'namelookup_time' => 0.0,
@@ -118,7 +118,7 @@ public function request(string $method, string $url, array $options = []): Respo
$onProgress = static function (...$progress) use ($onProgress, &$lastProgress, &$info) {
$progressInfo = $info;
$progressInfo['url'] = implode('', $info['url']);
unset($progressInfo['fopen_time'], $progressInfo['size_body']);
unset($progressInfo['size_body']);
if ($progress && -1 === $progress[0]) {
// Response completed
@@ -133,14 +133,14 @@ public function request(string $method, string $url, array $options = []): Respo
// Always register a notification callback to compute live stats about the response
$notification = static function (int $code, int $severity, ?string $msg, int $msgCode, int $dlNow, int $dlSize) use ($onProgress, &$info) {
$now = microtime(true);
$info['total_time'] = $now - $info['start_time'];
$info['total_time'] = microtime(true) - $info['start_time'];
if (STREAM_NOTIFY_PROGRESS === $code) {
$info['starttransfer_time'] = $info['starttransfer_time'] ?: $info['total_time'];
$info['size_upload'] += $dlNow ? 0 : $info['size_body'];
$info['size_download'] = $dlNow;
} elseif (STREAM_NOTIFY_CONNECT === $code) {
$info['connect_time'] += $now - $info['fopen_time'];
$info['connect_time'] = $info['total_time'];
$info['debug'] .= $info['request_header'];
unset($info['request_header']);
} else {
@@ -310,7 +310,7 @@ private static function dnsResolve(array $url, NativeClientState $multi, array &
throw new TransportException(sprintf('Could not resolve host "%s".', $host));
}
$info['namelookup_time'] += microtime(true) - $now;
$info['namelookup_time'] = microtime(true) - ($info['start_time'] ?: $now);
$multi->dnsCache[$host] = $ip = $ip[0];
$info['debug'] .= "* Added {$host}:0:{$ip} to DNS cache\n";
} else {
@@ -368,10 +368,9 @@ private static function createRedirectResolver(array $options, string $host, ?ar
return null;
}
$now = microtime(true);
$info['url'] = $url;
++$info['redirect_count'];
$info['redirect_time'] = $now - $info['start_time'];
$info['redirect_time'] = microtime(true) - $info['start_time'];
// Do like curl and browsers: turn POST to GET on 301, 302 and 303
if (\in_array($info['http_code'], [301, 302, 303], true)) {
@@ -80,7 +80,7 @@ public function getInfo(string $type = null)
$info = $this->info;
$info['url'] = implode('', $info['url']);
unset($info['fopen_time'], $info['size_body'], $info['request_header']);
unset($info['size_body'], $info['request_header']);
if (null === $this->buffer) {
$this->finalInfo = $info;
@@ -128,7 +128,6 @@ private function open(): void
$this->info['request_header'] .= implode("\r\n", $context['http']['header'])."\r\n\r\n";
// Send request and follow redirects when needed
$this->info['fopen_time'] = microtime(true);
$this->handle = $h = fopen($url, 'r', false, $this->context);
self::addResponseHeaders($http_response_header, $this->info, $this->headers, $this->info['debug']);
$url = ($this->resolveRedirect)($this->multi, $this->headers['location'][0] ?? null, $this->context);
@@ -146,7 +145,7 @@ private function open(): void
return;
} finally {
$this->info['starttransfer_time'] = $this->info['total_time'] = microtime(true) - $this->info['start_time'];
$this->info['pretransfer_time'] = $this->info['total_time'] = microtime(true) - $this->info['start_time'];
restore_error_handler();
}
@@ -267,6 +266,7 @@ private static function perform(NativeClientState $multi, array &$responses = nu
if (null !== $e || !$remaining || feof($h)) {
// Stream completed
$info['total_time'] = microtime(true) - $info['start_time'];
$info['starttransfer_time'] = $info['starttransfer_time'] ?: $info['total_time'];
if ($onProgress) {
try {

0 comments on commit a590829

Please sign in to comment.
You can’t perform that action at this time.