Is this even possible in PHP?
If not, what is the highest precision available?
Is this even possible in PHP?
If not, what is the highest precision available?
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.
system
need to spawn a shell and return output to PHP. Wouldn't that take a lot more than a nanosecond? If so, wouldn't it defeat the purpose of find time to nanosecond precision? Please advice. –
Perineuritis time_nanosleep()
which is the only function I know that exposes nanoseconds. –
Cyanotype Now with this extension it's nanosecond timing is possible http://pecl.php.net/hrtime . Yet it is a stopwatch class implemented to suite the highest possible resolution on different platforms.
As of PHP 7.3 there's also a crossplatform hrtime()
function in the core http://php.net/manual/en/function.hrtime.php.
hrtime()
's doc says "Returns an array of integers in the form [seconds, nanoseconds]." –
Clack microtime() is the highest precision using PHP's vocabulary. You can also make a system call by using Unix date
and specify %N
format if you need nanosecond accuracy. Unix ntp_gettime()
has even higher resolution and returns jitter/wander/stability/shift/calibration data.
© 2022 - 2024 — McMap. All rights reserved.