<?php
function retry(callable $fn, int $attempts = 3, int $delayMs = 200): mixed {
for ($i = 1; $i <= $attempts; $i++) {
try {
return $fn();
} catch (Throwable $e) {
error_log("retry: attempt $i/$attempts failed — {$e->getMessage()}");
if ($i === $attempts) throw $e;
usleep($delayMs * 1000 * $i); // linear back-off
}
}
// unreachable
}
$resp = retry(fn() => httpGet('https://flaky.example.com/data'));
Create a free account and build your private vault. Share publicly whenever you want.