Skip to content

Elapsed period

This is the number of microseconds between two points in time.

use Innmind\Time\Clock;

$clock = Clock::live();
$start = $clock->now();
// do some stuff
$end = $clock->now();

$elapsed = $end->elapsedSince($start);

$elapsed is an instance of Innmind\Time\ElapsedPeriod.

This is especially useful when working with network I/O to check for timeouts.

This example uses a monotonic clock internally to avoid the problem where the server clock re-synchronize and jump back in time. In this case $end is technically before $start but the elapsed period is still a positive int.

Info

Bear in mind that the monotonic clock only works on PointInTimes returned by $clock->now(). If ->elapsedSince() is called on points returned by $clock->at() it will compare the number of microseconds since epoch.