// Created on savesnippets.com · https://savesnippets.com/ZRUhkKfh7nIOEA getMessage(); $transient = preg_match('/timeout|reset|temporarily|HTTP 5\d\d/', $msg); if (!$transient || $attempt >= $maxAttempts) throw $e; $sleepMs = $baseMs * (2 ** ($attempt - 1)); $sleepMs += random_int(0, $sleepMs); // jitter usleep($sleepMs * 1000); goto retry; } } $json = withRetry(fn() => httpGet('https://flaky.api/users'));