5

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?

HappyDog
  • 1,230
  • 1
  • 18
  • 45
akukas
  • 555
  • 1
  • 6
  • 11
  • I'm pretty sure that `$_SERVER` is populated by the webserver processing the request. – Ash Mar 26 '15 at 21:41
  • IIRC correctly it is at the time the request is received. Let me see if I can find the docs for that. [Have a look here](http://stackoverflow.com/questions/28703822/measuring-the-time-of-php-scripts-using-requestrequest-time). – Jay Blanchard Mar 26 '15 at 21:41
  • $_SERVER is mostly data from apache. I'm guessing, but almost certainly the request_times are when apache started processing the request. – Marc B Mar 26 '15 at 21:41

2 Answers2

5

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:

igorsantos07
  • 4,456
  • 5
  • 43
  • 62
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

empiric
  • 7,825
  • 7
  • 37
  • 48
bigben3333
  • 435
  • 2
  • 9