Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is PHP's $_SERVER[REQUEST_TIME] set?

What happens on the server to set the request time? Does it take into account the timezone for which the server is configured?

I'm asking because I need to know, if I have a site that has a timezone set as a site-wide variable, and I compare something to the $_SERVER['REQUEST_TIME'] to know if it's expired, I'm not sure whether a timezone mismatch is possible.

like image 705
beth Avatar asked Jun 10 '13 16:06

beth


People also ask

What is $_ SERVER [' Request_time ']?

$_SERVER['REQUEST_TIME'] corresponds to the time when the request has started, the web server provides this data. time() actually runs a syscall in order to check the time when this line is called.

What is the $_ SERVER PHP_SELF variable explain with example?

$_SERVER['PHP_SELF'] variable. This array element points out the filename of the currently executing script. For example, if you run www.cyberciti.biz/index.php, $_SERVER['PHP_SELF'] would be /index.

How do I find my PHP SERVER name?

PHP: $_SERVER['PHP_SELF'] You can find the filename of the currently executing script by using $_SERVER['PHP_SELF']. Filename shown as output is relative to the root of the document.

What is $_ SERVER [' Document_root ']?

$_SERVER['DOCUMENT_ROOT'] returns. The document root directory under which the current script is executing, as defined in the server's configuration file.


1 Answers

$_SERVER's 'REQUEST_TIME' is a Unix timestamp. That should be enough information, but if it isn't: Unix timestamps are always UTC-based.

PHP Example

The notation for Unix timestamps in DateTime is to prefix the number with the at-sign ("@"). Then the second $timeZone parameter is ingored and defaults to "UTC" because it is a Unix timestamp which are always UTC based:

$requestTime = new DateTime("@$_SERVER[REQUEST_TIME]");

Gives:

class DateTime#1 (3) {
  public $date          => string(19) "2013-06-23 07:45:44"
  public $timezone_type => int(1)
  public $timezone      => string(6) "+00:00"
}

It is not even possible to force (by timestamp at construction) the DateTime object to a different timezone - only later on changing the timezone.

like image 101
Evert Avatar answered Sep 17 '22 15:09

Evert