From e0b72c4f74767ef6413dc7073f413ff2c37cad59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 16 Sep 2021 14:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-server/Service/Http.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/http-server/Service/Http.php b/http-server/Service/Http.php index 92f65495..c420c5f7 100644 --- a/http-server/Service/Http.php +++ b/http-server/Service/Http.php @@ -42,15 +42,13 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect public function onRequest(Request $request, Response $response): void { try { - $node = $this->router->radix_tree($Psr7Request = ScRequest::create($request)); - if (!($node instanceof Node)) { + if (!(($node = $this->router->radix_tree($Psr7Request = ScRequest::create($request))) instanceof Node)) { throw new RequestException(Constant::STATUS_404_MESSAGE, 404); } if (!(($psr7Response = $node->dispatch($Psr7Request)) instanceof ResponseInterface)) { $psr7Response = $this->transferToResponse($psr7Response); } - $request_time_float = $request->server['request_time_float'] - $request->server['request_time']; - $psr7Response->withHeader('Run-Time', microtime(true) - $request_time_float); + $psr7Response->withHeader('Run-Time', $this->_runTime($request)); } catch (Error | \Throwable $exception) { $psr7Response = $this->exceptionHandler->emit($exception, $this->response); } finally { @@ -60,6 +58,16 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect } + /** + * @param Request $request + * @return float + */ + private function _runTime(Request $request): float + { + return round(microtime(true) - ($request->server['request_time_float'] - $request->server['request_time']), 6); + } + + /** * @param mixed $responseData * @return ResponseInterface