Illuminate\Bus\PendingDispatchException) and queue workers (e.g., Illuminate\Queue\RetryableException). Can complement Laravel’s built-in retry mechanisms (e.g., retry() helper) or act as a standalone solution for custom backoff strategies.use Yriveiro\Backoff\Backoff;
$backoff = new Backoff(3); // 3 retries
$backoff->execute(fn() => $this->callExternalApi());
retry() helper (simpler for basic cases).spatie/backoff (more actively maintained).symfony/lock, stripe/stripe-php’s retry logic).composer require yriveiro/php-backoff.)retry() suffice?Illuminate\Queue\RetryableException).PDOException for deadlocks).retry(): For simple linear retries (e.g., retry(3, fn() => $this->callApi())).App\Exceptions\Handler).sleep() delays with the backoff package.retry() for simple cases.usleep(pow(2, $attempt) * 100)).declare(strict_types=1) adjustments).Illuminate\Foundation\Exceptions\Handler).array_merge vs. ... operator).monolog for logging).AppServiceProvider:
$this->app->singleton(Backoff::class, fn() => new Backoff(3, 100, 5000));
RetryService to encapsulate backoff logic:
class RetryService {
public function execute(Backoff $backoff, callable $callback) {
return $backoff->execute($callback);
}
}
handle() methods to use the backoff service:
public function handle() {
$this->retryService->execute($backoff, fn() => $this->processPayment());
}
$response = $this->retryService->execute($backoff, fn() => Http::post('...'));
sleep() calls.$backoff->setLogger($this->app->make(LoggerInterface::class));
retry_attempts_total).pestle/backoff or custom rate limiting).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Package incompatibility (PHP/Laravel) | Integration fails silently. | Test in staging; fallback to manual retries. |
| Unhandled exceptions | Infinite retries crash workers. | Whitelist retryable exceptions (e.g., RetryableException). |
| Downstream service permanently down | Retries waste resources. | Implement circuit breaker (e.g., ` |
How can I help you explore Laravel packages today?