第一步

编辑functions.php 添加函数

PLAINTEXT
function runTime(){

$timer = explode(' ', microtime());

return $timer[0] + $timer[1];

}
点击展开查看更多

第二步

编辑header.php<!DOCTYPE html>上面添加函数<?php define('START_TIME',runTime()); ?><!--开始计算-->

第三步

编辑footer.php在要显示的地方添加耗时:<?php echo round(runTime()-START_TIME,5); ?><!--计算结束显示-->这样就搞定了

第二种方法 推荐使用

PLAINTEXT
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;
}
点击展开查看更多
PLAINTEXT
页面耗时:<?php echo timer_stop();?>
点击展开查看更多

版权声明

作者: JunYan`Blog

链接: https://www.jinjun.top/posts/b33a/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

评论

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键