如何找到php执行时间?
我的网站上有大量PHP代码,我想知道处理的执行时间。我该怎么做如何找到php执行时间?,php,time,Php,Time,我的网站上有大量PHP代码,我想知道处理的执行时间。我该怎么做 <?php // large code // large code // large code // print execution time here ?> 您可以使用microtime作为PHP代码的开始和结束: <?php $time_start = microtime(true); sleep(1); $time_end = microtime(true); $time
<?php
// large code
// large code
// large code
// print execution time here
?>
您可以使用
microtime
作为PHP代码的开始和结束:
<?php
$time_start = microtime(true);
sleep(1);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "Process Time: {$time}";
// Process Time: 1.0000340938568
?>
可能值得注意的是,
$\u服务器['REQUEST\u TIME']
从5.1开始提供,但精度为秒。+1表示5.4开始时间超球如果以秒为单位测量,则表示您做错了。@Orangepill谢谢:)-我没有听清楚您最后的评论。如果使用双引号,则不需要卷发。相关:
<?php
sleep(1);
$time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
echo "Process Time: {$time}";
// Process Time: 1.0061590671539
?>