At what point in the startup process does PHP set the REQUEST_TIME variables

扶醉桌前 提交于 2019-12-22 09:17:22

问题


As noted in the PHP documentation, the $_SERVER superglobal array contains two elements, REQUEST_TIME and REQUEST_TIME_FLOAT, both of which contain the timestamp of the start of the request, in varying precision levels.

I am currently using the following snippet to include the time (in milliseconds) it took the server to generate the page in the footer of the page:

round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT'])*1000,2);

It returns an accurate value (can't really check, but it seems to match the time it takes the browser to start loading the page), but I am wondering which exact moment do the $_SERVER['REQUEST_TIME'] and $_SERVER['REQUEST_TIME_FLOAT'] variables contain the timestamp of? While I believe that the differences between those timestamps aren't significant, I would like to know which moment is the timestamp taken at. Is it the time when the request was sent, when the request was received, when PHP started parsing the document or something else?


回答1:


By checking PHP source code it seems most of the times it gets the initial request time from the SAPI itself - meaning from Apache, Nginx, CLI server, CGI... etc.

Sources:

  • $_SERVER['REQUEST_TIME'] definition
  • sapi_get_request_time() (SG() stands for "SAPI Global [value]")
  • php_apache_sapi_get_request_time()
  • sapi_module definitions [1] [2]



回答2:


$_SERVER['REQUEST_TIME'] and $_SERVER['REQUEST_TIME_FLOAT'], is the time when the request was received by your HTTP server.

A little warning regarding your php version: https://bugs.php.net/bug.php?id=64370



来源:https://stackoverflow.com/questions/29289392/at-what-point-in-the-startup-process-does-php-set-the-request-time-variables

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