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程序搭建的,只在测试网站上用过,所以本网站暂时没有使用。

版权声明:本文由 鹿泽笔记 原创发布。

本文链接:https://www.bailuze.com/18700.html

许可协议:本文标题《Typecho程序搭建的网站简单增加页面执行时间的方法》,转载请注明文章出处及原始链接。

鹿泽
鹿泽

深耕 SEO优化 十二年,从个人博客爱好者到专业谷歌优化顾问的成长之路。技术派SEO、全域流量技术运营专家,拥有多年从业经验,热衷于分析算法逻辑与推理的精准匹配。