Is this even possible in PHP?
If not, what is the highest precision available?
The time() function returns the current time in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).
The microtime() function returns the current Unix timestamp with microseconds.
By default, microtime() returns a string in the form "msec sec", where sec is the number of seconds since the Unix epoch (0:00:00 January 1,1970 GMT), and msec measures microseconds that have elapsed since sec and is also expressed in seconds as a decimal fraction.
currentTimeMillis() method returns the current time in milliseconds. The unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With