Browse Source

page time cost improved

master
filesite 3 years ago
parent
commit
288064ef59
  1. 11
      controller/Controller.php
  2. 2
      lib/FSC.php
  3. 2
      views/layout/main.php
  4. 11
      www/index.php

11
controller/Controller.php

@ -31,10 +31,6 @@ Class Controller { @@ -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 { @@ -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);

2
lib/FSC.php

@ -8,7 +8,7 @@ Class FSC { @@ -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);

2
views/layout/main.php

@ -17,7 +17,7 @@ include_once $viewFile; @@ -17,7 +17,7 @@ include_once $viewFile;
?>
<div class="footer">
&copy;FSC 2022 - execute time: <?php echo $page_time_cost;?> ms
&copy;FSC 2022 - execute time: {page_time_cost} ms
</div>
<script src="/js/js.cookie.min.js"></script>

11
www/index.php

@ -1,12 +1,13 @@ @@ -1,12 +1,13 @@
<?php
/* All php controller enter from here */
require_once __DIR__ . '/../lib/FSC.php';
require_once __DIR__ . '/../controller/Controller.php';
//run app
$start_time = microtime(true); //for time cost
$config = require_once __DIR__ . '/../conf/app.php';
$default_timezone = !empty($config['default_timezone']) ? $config['default_timezone'] : 'Asia/HongKong';
date_default_timezone_set($default_timezone);
$config['start_time'] = $start_time;
require_once __DIR__ . '/../lib/FSC.php';
require_once __DIR__ . '/../controller/Controller.php';
//run app
FSC::run($config);
Loading…
Cancel
Save