分享学习记录
互联网技术知识

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

赞(0)
文章名称:《Typecho程序搭建的网站简单增加页面执行时间的方法》
文章链接:https://www.bailuze.com/18700.html
本站所有文章,如无特殊说明或标注,均为本站原创发布。任何在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
本站专注于百度、搜狗、360、谷歌、bing等常见搜索引擎的优化,关键词排名的提高,诚意咨询邮箱526009505@qq.com
分享到