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

akukas picture akukas · Mar 26, 2015 · Viewed 7k times · Source

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?

Answer

igorsantos07 picture igorsantos07 · Jan 15, 2019

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: