douping1993 2011-07-13 13:54
浏览 93

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

If I do:

echo microtime(true);

I get the following results:

  • On my local Windows development environment I get a 4 digit precision (1310564569.4162 for example).
  • On my live CentOS (Linux) server I get a 2 digit precision (1310564569.41 for example).

OK so depending on the platform your running you get different precisions? Or this is a PHP/OS configuration?

Also from the microtime PHP docs:

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

Which OSes (or conditions/configurations) don't support this?

  • 写回答

1条回答 默认 最新

  • dongtai6741 2011-07-13 14:22
    关注

    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.

    by tuxradar.com

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献