Retry an HTTP call with exponential backoff in PHP

for ($attempt = 0; $attempt < 5; $attempt++) {
    try {
        return $client->request('GET', $url, ['timeout' => 3]);
    } catch (ConnectException $e) {
        usleep((int) ((2 ** $attempt) * 100000 + random_int(0, 50000)));
    }
}

throw new UpstreamUnavailable($url);