From c1711ca84531187ad7d3880df2ead3e1e5d3d0f6 Mon Sep 17 00:00:00 2001 From: beetle Date: Wed, 29 Jan 2020 15:06:06 +0400 Subject: [PATCH 1/3] Added return timer operation time --- PHPDaemon/Core/Timer.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/PHPDaemon/Core/Timer.php b/PHPDaemon/Core/Timer.php index 2946ac5a..85218c5d 100644 --- a/PHPDaemon/Core/Timer.php +++ b/PHPDaemon/Core/Timer.php @@ -30,6 +30,10 @@ class Timer * @var integer Current timeout holder */ public $lastTimeout; + /** + * @var float Timer start time + */ + protected $startTime; /** * @var boolean Is the timer finished? */ @@ -63,6 +67,7 @@ public function __construct($cb, $timeout = null, $id = null, $priority = null) } $this->id = $id; $this->cb = $cb; + $this->startTime = microtime(true); if ($this->eventLoop === null) { $this->eventLoop = EventLoop::$instance; } @@ -157,22 +162,25 @@ public function free() /** * Cancels timer by ID * @param integer|string $id Timer ID - * @return void + * @return float */ public static function cancelTimeout($id) { + $t=0; if (isset(self::$list[$id])) { - self::$list[$id]->cancel(); + $t = self::$list[$id]->cancel(); } + return $t; } /** * Cancels timer - * @return void + * @return float */ public function cancel() { $this->ev->del(); + return microtime(true) - $this->startTime; } /** From cc8910aa3889f0cb8de2ba285fdd55e49fd7f15a Mon Sep 17 00:00:00 2001 From: beetle Date: Wed, 19 Feb 2020 20:57:02 +0400 Subject: [PATCH 2/3] Added return timer operation time --- PHPDaemon/Core/Timer.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/PHPDaemon/Core/Timer.php b/PHPDaemon/Core/Timer.php index 85218c5d..29bc975d 100644 --- a/PHPDaemon/Core/Timer.php +++ b/PHPDaemon/Core/Timer.php @@ -166,11 +166,10 @@ public function free() */ public static function cancelTimeout($id) { - $t=0; if (isset(self::$list[$id])) { - $t = self::$list[$id]->cancel(); + return self::$list[$id]->cancel(); } - return $t; + return 0; } /** From d8fc2217a885543e8d1f4ab64fad7e9b830115af Mon Sep 17 00:00:00 2001 From: beetle Date: Wed, 19 Feb 2020 22:28:20 +0400 Subject: [PATCH 3/3] Added return timer operation time --- PHPDaemon/Core/Timer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/PHPDaemon/Core/Timer.php b/PHPDaemon/Core/Timer.php index 29bc975d..f3daf5ec 100644 --- a/PHPDaemon/Core/Timer.php +++ b/PHPDaemon/Core/Timer.php @@ -103,6 +103,7 @@ public function timeout($timeout = null) $this->lastTimeout = $timeout; } $this->ev->add($this->lastTimeout / 1e6); + $this->startTime = microtime(true); } /**