Home > php教程 > php手册 > php记录页面代码执行时间

php记录页面代码执行时间

WBOY
Release: 2016-05-25 16:50:55
Original
1106 people have browsed it

在php中要记录页面中代码执行时间我们只使用microtime函数生成时间,然后在最后把开始与结束时间相减即可解决了,核心代码如下:

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

上面为核心代码下面我们详细的来介绍一下,代码如下:

<?php 
$start_time=microtime(true); //获取程序开始执行的时间 
echo "hello world!<br />"; //你执行的代码 
$end_time=microtime(true);//获取程序执行结束的时间 
$total=$end_time-$start_time; //计算差值 
echo "此php文件中代码执行了{$total}秒"; 	
?>
Copy after login

               
               

本文地址:

转载随意,但请附上文章地址:-)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template