From 288064ef59121ba92472bbe9f82d65bd1e8b1ce5 Mon Sep 17 00:00:00 2001 From: filesite Date: Fri, 11 Mar 2022 18:31:55 +0800 Subject: [PATCH] page time cost improved --- controller/Controller.php | 11 ++++++----- lib/FSC.php | 2 +- views/layout/main.php | 2 +- www/index.php | 11 ++++++----- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/controller/Controller.php b/controller/Controller.php index ea88fa1..9ad7d2c 100644 --- a/controller/Controller.php +++ b/controller/Controller.php @@ -31,10 +31,6 @@ Class Controller { //include layout and view if (file_exists($layoutFile)) { - //show time cost - $end_time = microtime(true); - $page_time_cost = ceil( ($end_time - FSC::$app['start_time']) * 1000 ); //ms - ob_start(); include_once $layoutFile; @@ -43,7 +39,12 @@ Class Controller { //enable gzip ob_start('ob_gzhandler'); - echo $htmlCode; + + //show time cost + $end_time = microtime(true); + $page_time_cost = ceil( ($end_time - FSC::$app['start_time']) * 1000 ); //ms + echo str_replace('{page_time_cost}', $page_time_cost, $htmlCode); + ob_end_flush(); }else { throw Exception("Layout file not exist: {$layoutFile}", 500); diff --git a/lib/FSC.php b/lib/FSC.php index cdb962e..c278c02 100644 --- a/lib/FSC.php +++ b/lib/FSC.php @@ -8,7 +8,7 @@ Class FSC { //call function in controller public static function run($config = []) { - self::$start_time = microtime(true); + self::$start_time = !empty($config['start_time']) ? $config['start_time'] : microtime(true); try { self::loadController($config); diff --git a/views/layout/main.php b/views/layout/main.php index af90678..84bd2ad 100644 --- a/views/layout/main.php +++ b/views/layout/main.php @@ -17,7 +17,7 @@ include_once $viewFile; ?> diff --git a/www/index.php b/www/index.php index 77128c1..a3b845a 100644 --- a/www/index.php +++ b/www/index.php @@ -1,12 +1,13 @@