在我的方法中不同地方输出 microtime() 结果显示时间一样
服务器信息
回复内容: 在我的方法中不同地方输出 microtime() 结果显示时间一样
服务器信息
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算法精确的问题,它还是有误差的,具体的还是请楼下大神解答吧
