Switch to hrtime and display time to render in ms

This commit is contained in:
Belle Aerni 2023-06-20 05:20:24 -07:00
parent 8d9e894af8
commit c613271c48
2 changed files with 5 additions and 7 deletions

View file

@ -81,8 +81,8 @@ class AntAuth
{ {
setcookie("auth", "valid"); setcookie("auth", "valid");
$title = AntConfig::currentConfig('siteInfo.siteTitle'); $siteInfo = AntConfig::currentConfig('siteInfo');
header('WWW-Authenticate: Basic realm="' . $title . '"'); header('WWW-Authenticate: Basic realm="' . $siteInfo['siteTitle'] . '"');
http_response_code(401); http_response_code(401);
echo 'You must enter a valid username and password to access this page'; echo 'You must enter a valid username and password to access this page';
exit; exit;

View file

@ -23,7 +23,7 @@ class AntCMS
*/ */
public function renderPage(string $page) public function renderPage(string $page)
{ {
$start_time = microtime(true); $start_time = hrtime(true);
$content = $this->getPage($page); $content = $this->getPage($page);
$themeConfig = Self::getThemeConfig(); $themeConfig = Self::getThemeConfig();
@ -43,12 +43,10 @@ class AntCMS
]; ];
$pageTemplate = $this->antTwig->renderWithTiwg($pageTemplate, $params); $pageTemplate = $this->antTwig->renderWithTiwg($pageTemplate, $params);
$elapsed_time = (hrtime(true) - $start_time) / 1e+6;
$end_time = microtime(true);
$elapsed_time = round($end_time - $start_time, 4);
if (AntConfig::currentConfig('debug')) { if (AntConfig::currentConfig('debug')) {
$pageTemplate = str_replace('<!--AntCMS-Debug-->', '<p>Took ' . $elapsed_time . ' seconds to render the page. </p>', $pageTemplate); $pageTemplate = str_replace('<!--AntCMS-Debug-->', '<p>Took ' . $elapsed_time . ' milliseconds to render the page. </p>', $pageTemplate);
} }
return $pageTemplate; return $pageTemplate;