Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page