This example details the differences between time () and $ _ SERVER [REQUEST_TIME] in php.
What is the difference between time () and $ _ SERVER ['request _ time'] in php, I believe many people will, like me, question the main difference between the two. I will analyze it for you as follows:
1. time () gets the current system Timestamp
Int time (void ):
Returns the current Unix timestamp (returns the number of seconds from the Unix epoch (GMT 00:00:00, January 1, January 1, 1970) to the current time ).
Since PHP 5.1, the timestamp at the TIME when the REQUEST is initiated is saved in $ _ SERVER ['request _ time.
$ _ SERVER ["REQUEST_TIME"]: The timestamp of the start of the request. Available since PHP 5.1.0. PS: I believe that my friends who have better English can understand the explanation at a glance.
2. $ _ SERVER ["REQUEST_TIME"] gets the timestamp at the start of the request.
In short, both time () and $ _ SERVER ["REQUEST_TIME"] obtain the current timestamp, but time () returns the current Unix timestamp. $ _ SERVER ["REQUEST_TIME"] obtains the timestamp at the beginning of the request for php script, which is slightly different in time. In general usage, there is no big difference. However, when php executes too many programs and is too complex, the difference between the two will become larger. For example:
Instance code:
'; Echo date ('Y-m-d H: I: s', $ _ SERVER ['request _ time']); // get the timestamp when requesting this php script?>
The output result is as follows:
Summary:
Because sleep (5) sleeps for 5 seconds, and then uses time () to obtain the system timestamp, $ _ SERVER ['request _ time'] records the timestamp at which the REQUEST is initiated.
Therefore, the difference between the two is in the five seconds that $ _ SERVER ['request _ time'] is earlier than the timestamp obtained using TIME;