A Coder

Coding My Dream!

0%

不使用插件实现获得博客的PHP执行时间

经常逛博客发现很多朋友的博客上都有一个人PHP的计时比如页面执行了多少时间什么的,由于好奇,我也忍不住想知道我的页面执行了多少时间,于是开始在网上寻找解决办法!

在wordpress上可以使用如下方法:

因为wordpress本身带有页面执行时间的函数,我们只需要调用即可!

start.php页面添加如下代码:

<?php timer_start(); ?>

end.php页面添加如下代码:

页面执行时间:<?php timer_stop(1); ?> (s)

如果你使用的不是wordpress,当然不能使用上面的方法啦~ 但是你可以有另一种方案~

如下

在根目录下的index.php 文件的<php? 的下一行加入

function microtime_float()
{
list($usec, $sec) = explode(“ “, microtime());
return ((float)$usec + (float)$sec);
}

$time_start = microtime_float();

在末尾加入

$time_end = microtime_float();

$time = $time_end - $time_start;

echo “\n