How to get time in PHP with nanosecond precision?

Matt picture Matt · Nov 17, 2010 · Viewed 27.4k times · Source

Is this even possible in PHP?

If not, what is the highest precision available?

Answer

Jacob Relkin picture Jacob Relkin · Nov 17, 2010

The microtime function is what you're looking for.

PHP does not supply a function that has higher precision than microseconds.

You can use the system function to get the value straight from the machine if you are running Linux:

$nanotime = system('date +%s%N');

%s is the amount of seconds, appended by %N, which is the amount of nanoseconds.