Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Return current Unix timestamp with microseconds
microtime(bool $as_float = false): string|float
public function updateTime()
{
return $this->time = $this->useHighResolution ? \hrtime(true) * 1e-9 : \microtime(true);
}
public function getTime()
{
return $this->time = $this->useHighResolution ? \hrtime(true) * 1e-9 : \microtime(true);
}
public function getTime()
private function assertRunSlowerThan($minInterval)
{
$start = microtime(true);
$this->loop->run();
{
$start = microtime(true);
$this->loop->run();
$this->loop->run();
$end = microtime(true);
$interval = $end - $start;
$this->assertLessThan($interval, $minInterval);
$end = microtime(true);
$interval = $end - $start;
$this->assertLessThan($interval, $minInterval);
private function assertRunFasterThan($maxInterval)
{
$start = microtime(true);
$this->loop->run();
{
$start = microtime(true);
$this->loop->run();
$this->loop->run();
$end = microtime(true);
$interval = $end - $start;
$this->assertLessThan($maxInterval, $interval);
$end = microtime(true);
$interval = $end - $start;
$this->assertLessThan($maxInterval, $interval);
public function testExecuteExampleWithUncaughtExceptionShouldNotRunLoop()
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 11-uncaught.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 11-uncaught.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 11-uncaught.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 11-uncaught.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
public function testExecuteExampleWithUndefinedVariableShouldNotRunLoop()
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 12-undefined.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 12-undefined.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 12-undefined.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 12-undefined.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
public function testExecuteExampleWithExplicitStopShouldNotRunLoop()
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 21-stop.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 21-stop.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 21-stop.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 21-stop.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
public function testExecuteExampleWithExplicitStopInExceptionHandlerShouldNotRunLoop()
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 22-uncaught-stop.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 22-uncaught-stop.php 2>/dev/null');
$time = microtime(true) - $time;
{
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 22-uncaught-stop.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
$time = microtime(true);
exec(escapeshellarg(PHP_BINARY) . ' 22-uncaught-stop.php 2>/dev/null');
$time = microtime(true) - $time;
$this->assertLessThan(1.0, $time);
}
$this->expectCallableOnce()
);
$start = microtime(true);
$this->loop->run();
);
$start = microtime(true);
$this->loop->run();
$this->loop->run();
$end = microtime(true);
$interval = $end - $start;
$this->assertGreaterThan(0.04, $interval);
$end = microtime(true);
$interval = $end - $start;
$this->assertGreaterThan(0.04, $interval);