php - PHP 在不同操作系统下的微秒精度是多少?

标签 php operating-system precision microtime

如果我这样做:

echo microtime(true);

我得到以下结果:

  • 在我的本地 Windows 开发环境中,我获得了 4 位精度(例如 1310564569.4162)。
  • 在我的实时 CentOS (Linux) 服务器上,我得到了 2 位数的精度(例如 1310564569.41)。

好吧,根据你运行的平​​台,你会得到不同的精度?或者这是一个 PHP/OS 配置?

同样来自 microtime PHP 文档:

This function is only available on operating systems that support the gettimeofday() system call.

哪些操作系统(或条件/配置)不支持此功能?

最佳答案

If you pass true to microtime() as its only parameter, PHP will return the time in a more obvious format - seconds.microseconds, like this: 1174676587.5996

When using microtime(), keep in mind that the return value is a floating-point number. There is a setting in your php.ini file called "precision", which sets the number of significant digits to show in floating-point numbers - note that is significant digits, not decimal places, which means your return value from microtime() may not be as precise as you want. Above, for example, you can see we only have four decimal places returned - this is because php.ini defaults precision to 14, and there are ten digits before the decimal place.

If you increase the value of precision up to, say, 18, and run microtime() again, you will get results that are more accurate: 1174677004.8997819.

来自tuxradar.com

关于php - PHP 在不同操作系统下的微秒精度是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6680053/

相关文章:

php - 如何通过 .htaccess 保护 phpmyadmin 访问

php - Yii2 - 基于 dropDownList 显示表单字段

php - 从函数中查询

operating-system - 如果我增加页面大小,则内部碎片会增加。如何?

python - 由于比例因子和偏移量,导入 Python 时 NetCDF 数据精度下降

php - 如何使用 composer 安装 PHPWord 库

compilation - 为移动设备编译 Haiku OS

Android 操作系统框架 - 将单个可执行文件构建为共享对象

go - 为什么 0.1 + 0.2 在 Google Go 中得到 0.3?

double - 双类型的 OpenCL 问题