Typecho添加网站加载时间
直接在主题下的 functions.php 中加入以下代码即可:
/**
* 加载时间
* @return bool
*/
function timer_start() {
global $timestart;
$mtime = explode( ' ', microtime() );
$timestart = $mtime[1] + $mtime[0];
return true;
}
timer_start();
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;
}
然后在要显示的地方(一般是在网站底部主题foot.php文件)调用即可:
网页加载耗时:<?php echo timer_stop();?>
—— THE END ——
最后更新于 2022-06-23「部分内容存在时效性,如有失效请留言反馈」
除注明外为 羽翼博客 原创文章,转载请注明出处。
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
本文链接:https://www.886a.top/archives/372.html