From a6dff412786ee7100ca09aa4f9fd49160a07e223 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 21 Aug 2023 17:37:29 +0200 Subject: [PATCH] wip #6202 --- src/PHP.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PHP.php b/src/PHP.php index bed218a..5ac41bf 100644 --- a/src/PHP.php +++ b/src/PHP.php @@ -78,12 +78,21 @@ class PHP } - public static function retryOnError(callable $callback, $attempts = 3) + /** + * @param callable $callback + * @param $attempts int + * @param $pauseBetweenAttemps float + * @return mixed + */ + public static function retryOnError(callable $callback, $attempts = 3, $pauseBetweenAttemps = 0) { try { return call_user_func($callback); } catch (\Exception $e) { if ($attemps > 0) { + if ($pauseBetweenAttemps > 0) { + usleep($pauseBetweenAttemps / 1000000); + } return self::retryOnError($callback, $attempts - 1); } throw $e; -- 2.39.5