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 {
//include layout and view //include layout and view
if (file_exists($layoutFile)) { 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(); ob_start();
include_once $layoutFile; include_once $layoutFile;
@ -43,7 +39,12 @@ Class Controller {
//enable gzip //enable gzip
ob_start('ob_gzhandler'); 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(); ob_end_flush();
}else { }else {
throw Exception("Layout file not exist: {$layoutFile}", 500); throw Exception("Layout file not exist: {$layoutFile}", 500);

2
lib/FSC.php

@ -8,7 +8,7 @@ Class FSC {
//call function in controller //call function in controller
public static function run($config = []) { public static function run($config = []) {
self::$start_time = microtime(true); self::$start_time = !empty($config['start_time']) ? $config['start_time'] : microtime(true);
try { try {
self::loadController($config); self::loadController($config);

2
views/layout/main.php

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

11
www/index.php

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