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

2

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?

Illuminism answered 26/3, 2015 at 21:38 Comment(3)
I'm pretty sure that $_SERVER is populated by the webserver processing the request.Battaglia
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.Complacence
$_SERVER is mostly data from apache. I'm guessing, but almost certainly the request_times are when apache started processing the request.Turbine
H
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:

Handpick answered 15/1, 2019 at 6:7 Comment(2)
Is $_SERVER["REQUEST_TIME_FLOAT"] always defined ?Allspice
Yep. It gets added as soon as PHP starts processing the request, as all $_SERVER contents.Handpick
S
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

Sanious answered 26/3, 2015 at 21:54 Comment(1)
What is your source on this?Illuminism

© 2022 - 2024 — McMap. All rights reserved.