开发者

What's the microseconds precision in PHP under different OSes?

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 d开发者_StackOverflow社区ifferent 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜