第一步
编辑functions.php 添加函数
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); ?><!--计算结束显示-->
这样就搞定了
第二种方法 推荐使用
- 在当前主题的functions.php文件添加下面的代码:
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;
}
- 在要显示加载时间的位置添加调用代码 一般都是
footed
和post
页面
页面耗时:<?php echo timer_stop();?>
- 保存后,到前台刷新页面即可显示加载时间。
最新评论
我现在基本都不是用QQ了,电脑没装,手...
我成为了范例 😃
看起来很完美。
1ro.cn 还收不,怎么联系不到人
你的feed貌似有点问题。你看下。`v...
哈哈哈,路过。看到了