In short, both time () and $ _ SERVER [REQUEST_TIME] obtain the time, however, time returns the current Unix timestamp while $ _ SERVER [REQUEST_TIME] returns the timestamp at the beginning of the request, which is slightly different. In short, both time () and $ _ SERVER ["REQUEST_TIME"] obtain time, however, time returns the current Unix Timestamp and $ _ SERVER ["REQUEST_TIME"] returns the timestamp at the beginning of the request, which is slightly different.
Script ec (2); script
1) time () Get 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. You can understand all The explanations at a glance.
2) $ _ SERVER ["REQUEST_TIME"]Get the request start Timestamp
Instance code:
| The Code is as follows: |
|
Date_default_timezone_set ('prc ');
Sleep (5); // php script sleep for 5 seconds
Echo date ('Y-m-d H: I: s', time (); // obtain the timestamp of the current system time
Echo' ';
Echo date ('Y-m-d H: I: s', $ _ SERVER ['request _ time']); // obtain the timestamp when requesting this php script
?> |
The output result is as follows:
Conclusion:
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, $ _ SERVER ['request _ time'] is 5 seconds earlier than the timestamp obtained using TIME ().