Home >Backend Development >PHP Tutorial >PHP records page code execution time_PHP tutorial

PHP records page code execution time_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:16:35982browse

To record the code execution time in the page in php, we only use the microtime function to generate the time, and then subtract the start and end time at the end to solve the problem.

Core Code

The code is as follows
 代码如下  

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

$t1 = microtime(true);
// ...execute code ...
$t2 = microtime(true);
echo 'Time consuming'.round($t2-$t1,3).'Seconds';

The above is the core code, let’s introduce it in detail
 代码如下  


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

The code is as follows

$start_time=microtime(true); //Get the time when the program starts executing
echo "hello world!
"; //The code you execute
$end_time=microtime(true);//Get the time when program execution ends
$total=$end_time-$start_time; //Calculate the difference
echo "The code in this php file was executed for {$total} seconds";
?>

http://www.bkjia.com/PHPjc/372541.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/372541.htmlTechArticle
In php, to record the code execution time in the page, we only use the microtime function to generate the time, and then at the end put the start and This can be solved by subtracting the end time. The core code is as follows...
Statement:
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