计算 PHP 脚本执行时间的 PHP 程序


要计算 PHP 脚本的执行时间,代码如下 −

示例

 实时演示

<?php
$start = microtime(true);
$val=1;
for($i = 1; $i <=1500; $i++)
{
   $val++;
}
$end = microtime(true);
$exec_time = ($end - $start);
echo "The execution time of the PHP script is : ".$exec_time." sec";
?>

输出

The execution time of the PHP script is : 1.69 sec

‘Microtime’ 函数可用于检查 PHP 脚本执行完成所花费的时间。当代码开始执行时,记录时间,代码完成后,生成另一个时间戳,结束时间和开始时间之间的差值就是脚本完成其执行所花费的时间。

更新于: 02-Jul-2020

622 个浏览量

开启你的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.