AlexV
AlexV

Reputation: 23108

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

If I do:

echo microtime(true);

I get the following results:

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?

Upvotes: 3

Views: 1026

Answers (1)

Watze
Watze

Reputation: 21

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

Upvotes: 2

Related Questions