diff --git a/src/Commands/Concerns/InteractsWithIO.php b/src/Commands/Concerns/InteractsWithIO.php index bdb87f9ad..d8c0fb0ed 100644 --- a/src/Commands/Concerns/InteractsWithIO.php +++ b/src/Commands/Concerns/InteractsWithIO.php @@ -95,20 +95,23 @@ public function requestInfo($request, $verbosity = null) $url = parse_url($request['url'], PHP_URL_PATH) ?: '/'; $duration = number_format(round($request['duration'], 2), 2, '.', ''); - $memory = number_format(round($request['memory'] ?? memory_get_usage() / 1024 / 1204, 2), 2, '.', ''); + + $memory = isset($request['memory']) + ? (number_format($request['memory'] / 1024 / 1204, 2, '.', '').' mb ') + : ''; ['method' => $method, 'statusCode' => $statusCode] = $request; - $dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration.$memory) - 19, 0)); + $dots = str_repeat('.', max($terminalWidth - strlen($method.$url.$duration.$memory) - 16, 0)); if (empty($dots) && ! $this->output->isVerbose()) { - $url = substr($url, 0, $terminalWidth - strlen($method.$duration) - 15 - 3).'...'; + $url = substr($url, 0, $terminalWidth - strlen($method.$duration.$memory) - 15 - 3).'...'; } else { $dots .= ' '; } $this->output->writeln(sprintf( - ' %s %s %s %s%s mb %s ms', + ' %s %s %s %s%s%s ms', match (true) { $statusCode >= 500 => 'red', $statusCode >= 400 => 'yellow', diff --git a/src/Stream.php b/src/Stream.php index e16ba3cdb..9d959d9c4 100644 --- a/src/Stream.php +++ b/src/Stream.php @@ -21,6 +21,7 @@ public static function request(string $method, string $url, int $statusCode, flo 'type' => 'request', 'method' => $method, 'url' => $url, + 'memory' => memory_get_usage(), 'statusCode' => $statusCode, 'duration' => $duration, ])."\n"); diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 43ec5174b..5ba951bf8 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -54,7 +54,7 @@ public function test_request() 'method' => 'GET', 'url' => 'http://127.0.0.1/welcome', 'statusCode' => '200', - 'memory' => 23.43, + 'memory' => 17393560, 'duration' => 10, ]); @@ -62,7 +62,7 @@ public function test_request() 'method' => 'POST', 'url' => 'http://127.0.0.1:8080', 'statusCode' => '404', - 'memory' => 26.43, + 'memory' => 20393560, 'duration' => 1234, ]); @@ -70,14 +70,14 @@ public function test_request() 'method' => 'POST', 'url' => 'http://127.0.0.1:8080/'.str_repeat('foo', 100), 'statusCode' => 500, - 'memory' => 28.43, + 'memory' => 30393560, 'duration' => 4567854, ]); $this->assertEquals(<<<'EOF' - 200 GET /welcome .......... 23.43 mb 10.00 ms - 404 POST / .............. 26.43 mb 1234.00 ms - 500 POST /foofoofoofoofoofo... 28.43 mb 4567854.00 ms + 200 GET /welcome ......... 14.11 mb 10.00 ms + 404 POST / ............. 16.54 mb 1234.00 ms + 500 POST /foofoofo... 24.65 mb 4567854.00 ms EOF, $output->fetch()); }