From 0ab8f2f05c43f64579883fbf7fa588c7acd6b624 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 18 Feb 2022 12:25:54 +0000 Subject: [PATCH 1/2] error handler for cli loop --- src/CLI/Console.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/CLI/Console.php b/src/CLI/Console.php index 2fb28ed..f3cb3c6 100644 --- a/src/CLI/Console.php +++ b/src/CLI/Console.php @@ -190,16 +190,24 @@ static public function isInteractive(): bool /** * @param callable $callback * @param int $sleep in seconds + * @param callable $onError */ - static public function loop(callable $callback, $sleep = 1 /* 1 second */): void + static public function loop(callable $callback, $sleep = 1 /* 1 second */, callable $onError = null): void { gc_enable(); $time = 0; while (!connection_aborted() || PHP_SAPI == "cli") { - - $callback(); + try { + $callback(); + } catch(\Exception $e) { + if($onError != null) { + $onError($e); + } else { + throw $e; + } + } sleep($sleep); From 186d564e4e086b08fee1041cd0b7b8df561808d8 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 19 Feb 2022 00:00:41 +0200 Subject: [PATCH 2/2] Removed PHP 7.4 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ee1fba6..3ba22f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: -- 7.4 - 8.0 - nightly