执行时间只能做个参考,并不是特别精确,因为输出了时间之后,还进行了运算。有人说这些代码出自Willin Kan,具体我也不是很清楚。
打开根目录 index.php
在/** 载入配置支持 */上面加上
/**
* 加载时间
* @return bool
*/
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime() );
$timestart = $mtime[1] + $mtime[0];
return true;
}
timer_start();
打开模板文件/footer.php
在合适位置加上
Total <?php echo timer_stop();?>
在最后加上
<?php
function timer_stop( $display = 0, $precision = 3 ) {
global $timestart, $timeend;
$mtime = explode( ' ', microtime() );
$timeend = $mtime[1] + $mtime[0];
$timetotal = number_format( $timeend - $timestart, $precision );
$r = $timetotal < 1 ? $timetotal * 1000 . " ms" : $timetotal . " s";
if ( $display ) {
echo $r;
}
return $r;
}
?>
这样就可以了,由于我的网站是WordPress程序搭建的,只在测试网站上用过,所以本网站暂时没有使用。
👋 感谢您的观看!
© 版权声明
THE END