84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
在我的方法中不同地方输出 microtime() 结果显示时间一样
服务器信息
认证高级PHP讲师
microtime又不是unique,谁规定它不能输出一样的时间了?
注:PHP的microtime直接采用了系统中gettimeofday函数的结果进行输出,没有进过任何缓存处理,如果结果一样,这锅PHP也不背。
PHP 5.3.28 中 microtime 的实现
static void _php_gettimeofday(INTERNAL_FUNCTION_PARAMETERS, int mode) { zend_bool get_as_float = 0; struct timeval tp = {0}; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &get_as_float) == FAILURE) { return; } if (gettimeofday(&tp, NULL)) { RETURN_FALSE; } if (get_as_float) { RETURN_DOUBLE((double)(tp.tv_sec + tp.tv_usec / MICRO_IN_SEC)); } if (mode) { timelib_time_offset *offset; offset = timelib_get_time_zone_info(tp.tv_sec, get_timezone_info(TSRMLS_C)); array_init(return_value); add_assoc_long(return_value, "sec", tp.tv_sec); add_assoc_long(return_value, "usec", tp.tv_usec); add_assoc_long(return_value, "minuteswest", -offset->offset / SEC_IN_MIN); add_assoc_long(return_value, "dsttime", offset->is_dst); timelib_time_offset_dtor(offset); } else { char ret[100]; snprintf(ret, 100, "%.8F %ld", tp.tv_usec / MICRO_IN_SEC, tp.tv_sec); RETURN_STRING(ret, 1); } }
微秒本来就是这样,记得老师讲过关于php算法精确的问题,它还是有误差的,具体的还是请楼下大神解答吧
echo microtime(); sleep(1);echo microtime(); ?>
microtime又不是unique,谁规定它不能输出一样的时间了?
注:PHP的microtime直接采用了系统中gettimeofday函数的结果进行输出,没有进过任何缓存处理,如果结果一样,这锅PHP也不背。
PHP 5.3.28 中 microtime 的实现
微秒本来就是这样,记得老师讲过关于php算法精确的问题,它还是有误差的,具体的还是请楼下大神解答吧
echo microtime();
sleep(1);
echo microtime();
?>