This article describes in detail the difference between time () and $_server[request_time] usage in PHP. Share to everyone for your reference. The specific analysis is as follows:
The simple Time () and $_server["Request_time"] are all time, but it returns the current Unix timestamp and $_server["Request_time" to get the timestamp at the start of the request, slightly different.
1. Time () Gets the current system timestamp
int time (void):
Returns the current UNIX timestamp (returns the number of seconds since the Unix era (GMT January 1, 1970 00:00:00) to the current time. )
The timestamp that originated at the time of the request was saved from PHP 5.1 in $_server[' Request_time '.
$_server["Request_time"]: The timestamp of the start of the REQUEST. Available since PHP 5.1.0. I can see the explanation.
2. $_server["Request_time"] gets the time stamp at the start of the request
Instance code:
Copy Code code as follows:
<?php
Date_default_timezone_set (' PRC ');
Sleep (5);//php script sleeps 5 seconds
echo Date (' y-m-d h:i:s ', Time ());//get timestamp of current system time
echo ' echo Date (' y-m-d h:i:s ', $_server[' request_time ');/time stamp when requesting this PHP script
?>
The results of the output screenshot are as follows:
Conclusion:
Because Sleep (5) Sleeps for 5 seconds, and then gets the system timestamp with time (), $_server[' Request_time ' records the timestamp at the time the request was initiated. So $_server[' Request_time '] is 5 seconds earlier than the timestamp obtained with time ()
I hope this article will help you with your PHP program design.