美文网首页小蒋同学
php 记录代码 / 页面执行时间

php 记录代码 / 页面执行时间

作者: 小蒋同学v | 来源:发表于2019-11-16 19:10 被阅读0次

代码如下:

$t1 = microtime(true);
// ... 执行代码 ...
$t2 = microtime(true);
echo '耗时 '.round($t2-$t1, 3).' 秒';

microtime() 如果带有 true 参数,将返回一个浮点类型。

这样 t1 和 t2 得到的就是两个浮点数,相减之后得到之间的差。

由于浮点的位数很长,或者说不确定,所以再用 round() 取出小数点后 3 位。

相关文章

网友评论

    本文标题:php 记录代码 / 页面执行时间

    本文链接:https://www.haomeiwen.com/subject/sktuictx.html