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?
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']
definitionsapi_get_request_time()
(SG()
stands for "SAPI Global [value]")php_apache_sapi_get_request_time()
sapi_module
definitions [1] [2]