How to find php execution time? [duplicate]

喜你入骨 提交于 2021-02-05 21:53:11

问题


I have a large PHP code in my website, I want to know the execution time of processing. How can I do this?

<?php
// large code
// large code
// large code

// print execution time here
?>

回答1:


You can use microtime as the start and end of your PHP code:

<?php
    $time_start = microtime(true);
    sleep(1);
    $time_end = microtime(true);
    $time = $time_end - $time_start;
    echo "Process Time: {$time}";
    // Process Time: 1.0000340938568
?>

As of PHP 5.4.0, there is no need to get start time at the beginning, the $_SERVER superglobal array already has it:

<?php
    sleep(1);
    $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"];
    echo "Process Time: {$time}";
    // Process Time: 1.0061590671539
?>


来源:https://stackoverflow.com/questions/17035859/how-to-find-php-execution-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!