Measuring the time of PHP scripts - Using $_SERVER['REQUEST_TIME']

后端 未结 1 405
梦谈多话
梦谈多话 2021-01-23 02:08

Are this methods a reliable way to measure a script:

$time = ($_SERVER[\'REQUEST_TIME_FLOAT\'] - $_SERVER[\'REQUEST_TIME\']);

or

$tim

相关标签:
1条回答
  • 2021-01-23 02:53
    1. $time = ($_SERVER['REQUEST_TIME_FLOAT'] - $_SERVER['REQUEST_TIME']);

    This will never give you execution time of you PHP script. Because both the values are used for storing start of request. The difference is, $_SERVER['REQUEST_TIME_FLOAT'] is more precise and stores time value with microsecond precision, while $_SERVER['REQUEST_TIME'] in seconds.

    1. $time = (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);

    I guess this is what should be used at the end of the PHP script and I think you know why.

    Also keep in mind $_SERVER['REQUEST_TIME_FLOAT'] is available since PHP 5.4.0.

    0 讨论(0)
提交回复
热议问题