Name

microtime()

Synopsis

    mixed microtime ( [bool float_output] )

The microtime() function returns a highly accurate reading of the current time. When called without any parameters, this returns the current system time in seconds and microseconds, ordered microseconds first. For example: 0.82112000 1174676574. If you pass true to microtime(), PHP will return the time in the more useful format of 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 that sets the number of significant digits to show in floating-point numbers, 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 significant digits, and there are 10 digits before the decimal place.

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

Get PHP in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.