鹿泽笔记 - 记录互联网技术知识,工作与生活点滴的个人博客

Typecho程序搭建的网站简单增加页面执行时间的方法

执行时间只能做个参考,并不是特别精确,因为输出了时间之后,还进行了运算。有人说这些代码出自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
喜欢就支持一下吧
点赞0 分享