php中time()与$_SERVER[REQUEST_TIME]用法区别
程序员文章站
2022-06-28 23:44:14
本文实例详细讲述了php中time()与$_server[request_time]用法的区别。分享给大家供大家参考。具体分析如下:
简单的说time()与$_serve...
本文实例详细讲述了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"] 得到请求开始时的时间戳
实例代码:
复制代码 代码如下:
<?php
date_default_timezone_set('prc');
sleep(5);//php脚本睡5秒
echo date('y-m-d h:i:s',time());//获取当前系统时间的时间戳
echo '<hr />';
echo date('y-m-d h:i:s',$_server['request_time']);//得到请求此php脚本时的时间戳
?>
date_default_timezone_set('prc');
sleep(5);//php脚本睡5秒
echo date('y-m-d h:i:s',time());//获取当前系统时间的时间戳
echo '<hr />';
echo date('y-m-d h:i:s',$_server['request_time']);//得到请求此php脚本时的时间戳
?>
输出结果截图如下:
结论:
因为sleep(5)睡了5秒,之后用time()获取系统的时间戳,$_server['request_time']则记录了发起此请求时刻的时间戳。所以$_server['request_time']比用time()获取的时间戳早5秒
希望本文所述对大家的php程序设计有所帮助。
推荐阅读
-
PHP中return 和 exit 、break和contiue 区别与用法
-
PHP中exec与system用法区别分析
-
解析mysql中UNIX_TIMESTAMP()函数与php中time()函数的区别
-
php中sprintf与printf函数用法区别解析
-
php中静态类与静态变量用法的区别分析
-
php中time()与$_SERVER[REQUEST_TIME]用法区别
-
PHP中VC6、VC9、TS、NTS版本的区别与用法详解
-
解析mysql中UNIX_TIMESTAMP()函数与php中time()函数的区别_PHP教程
-
php中$_GET,$_POST,$_REQUEST用法与区别分析_PHP教程
-
PHP中return 和 exit 、break和contiue 区别与用法_PHP