Skip to content

Commit 3229ffd

Browse files
Use hrtime over microtime
1 parent c1c6e90 commit 3229ffd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"php": "^5.4 || ^7.0",
1515
"psr/log": "^1.0",
1616
"php-http/client-common": "^1.9 || ^2.0",
17-
"php-http/message": "^1.0"
17+
"php-http/message": "^1.0",
18+
"symfony/polyfill-php73": "^1.17"
1819
},
1920
"require-dev": {
2021
"phpspec/phpspec": "^2.5",

src/LoggerPlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public function __construct(LoggerInterface $logger, Formatter $formatter = null
3131

3232
protected function doHandleRequest(RequestInterface $request, callable $next, callable $first)
3333
{
34-
$start = microtime(true);
34+
$start = hrtime(true)/1E6;
3535
$this->logger->info(sprintf("Sending request:\n%s", $this->formatter->formatRequest($request)), ['request' => $request]);
3636

3737
return $next($request)->then(function (ResponseInterface $response) use ($request, $start) {
38-
$milliseconds = (int) round((microtime(true) - $start) * 1000);
38+
$milliseconds = (int) round(hrtime(true)/1E6 - $start);
3939
$this->logger->info(
4040
sprintf("Received response:\n%s\n\nfor request:\n%s", $this->formatter->formatResponse($response), $this->formatter->formatRequest($request)),
4141
[
@@ -47,7 +47,7 @@ protected function doHandleRequest(RequestInterface $request, callable $next, ca
4747

4848
return $response;
4949
}, function (Exception $exception) use ($request, $start) {
50-
$milliseconds = (int) round((microtime(true) - $start) * 1000);
50+
$milliseconds = (int) round((hrtime(true)/1E6 - $start));
5151
if ($exception instanceof Exception\HttpException) {
5252
$this->logger->error(
5353
sprintf("Error:\n%s\nwith response:\n%s\n\nwhen sending request:\n%s", $exception->getMessage(), $this->formatter->formatResponse($exception->getResponse()), $this->formatter->formatRequest($request)),

0 commit comments

Comments
 (0)