您好,欢迎访问一九零五行业门户网

php中time()与$_SERVER["REQUEST_TIME"]比较

简单的说time()与$_server[request_time]都是获得时间了,但time返回当前的 unix 时间戳而$_server[request_time]得到请求开始时的时间戳了了,稍有区别哦。
1) time() 获取当前的系统时间戳
int time(void) :
返回当前的 unix 时间戳 (返回自从 unix 纪元(格林威治时间 1970 年 1 月 1 日 00:00:00)到当前时间的秒数。 )
自 php 5.1 起在 $_server['request_time'] 中保存了发起该请求时刻的时间戳。
$_server[request_time] :the timestamp of the start of the request. available since php 5.1.0. 一看解释就都明白了
2) $_server[request_time] 得到请求开始时的时间戳
实例代码:
 代码如下 复制代码
输出结果截图如下:
结论:
因为sleep(5)睡了5秒,之后用time()获取系统的时间戳,$_server['request_time']则记录了发起此请求时刻的时间戳。所以$_server['request_time']比用time()获取的时间戳早5秒
其它类似信息

推荐信息