Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Retry Laravel Package

keboola/retry

A lightweight PHP library for retrying failing operations with configurable backoff strategies, maximum attempt limits, and exception handling. Useful for making API calls, database queries, and other unreliable tasks more resilient without writing custom retry loops.

Deep Wiki
Context7

The library for repeatable and retryable operations

Frequently asked questions about Retry
How do I install keboola/retry in a Laravel project?
Install it with Composer using composer require keboola/retry; the package is pulled from Packagist and autoloaded through your existing vendor/autoload.php. No service provider, facade, or config file registration is required because the library is framework-agnostic. Once installed you can call it from controllers, console commands, jobs, or service classes.
Is keboola/retry a Laravel package or a plain PHP library?
It is a plain PHP library with no dependency on the Laravel framework, which is why it also works in Symfony, plain PHP scripts, and CLI tools. Laravel projects simply benefit from Composer autoloading, so the classes are available anywhere in your app. Think of it as a small utility you wrap around unreliable code rather than a Laravel integration.
How do I retry a failing API call using keboola/retry?
Wrap the operation in a PHP closure and pass that callable to the library, which will execute it repeatedly until it succeeds or the attempt limit is reached. Any exception thrown inside the closure signals a failure and triggers the next attempt. This keeps your HTTP client, database, or filesystem code unchanged and free of hand-written while loops.
How do I configure the maximum number of retry attempts?
The library exposes configuration for the maximum number of attempts, so you decide how many times a fragile callable is executed before the failure is surfaced. Set this deliberately: a high limit on a slow external API can multiply your worst-case latency. When combined with queue workers or HTTP timeouts, keep the total possible runtime below your job or request timeout.
Can I add a delay or sleep between retries?
Yes, the delay between attempts is configurable, which lets a downstream service recover from a brief blip before you hit it again. A short pause is usually enough for transient network or database errors, and a delay of zero is useful in tests to avoid slow suites. Remember that sleeping blocks the current PHP process, so keep delays modest in web requests.
Does keboola/retry support exponential backoff?
The library is intentionally minimal: its documented knobs are the maximum attempt count and the delay between attempts, so the built-in behaviour is a straightforward retry loop. If you need exponential or jittered backoff, implement that logic yourself around the callable or inside it. For Laravel HTTP calls specifically, Laravel's own retry helper with a backoff callback can be a simpler fit.
What happens when all retry attempts fail?
When the attempt limit is exhausted, the failure is not swallowed: the exception from the last execution propagates so your application can log it, alert, or fail the job normally. That makes the library safe to use in transaction-like flows where silent failure would be worse than an error. Catch the exception at the call site if you want to return a fallback value instead.
Can I use keboola/retry inside Laravel queue jobs?
Yes, wrapping an unreliable step inside a job is a common pattern, but be aware that Laravel queues already have their own tries and backoff settings. Stacking both means a failing job may be retried many more times than you expect, so either rely on queue retries or keep the in-job attempt limit small. Also ensure the combined retry time stays within the worker timeout so jobs are not killed mid-attempt.
How do I test code that uses keboola/retry?
Because the library just invokes a callable, you can test the surrounding code by mocking the underlying client so it throws once and then succeeds, and assert the operation completed. Configure a zero or near-zero delay in your test environment so the suite does not sleep. For unit tests of your own logic, injecting a fake retry wrapper or a small interface keeps things fast and deterministic.
What are the alternatives to keboola/retry for Laravel developers?
Laravel ships retry support in several places: Http::retry with a backoff callback for HTTP calls, and the tries and backoff properties on queued jobs. Guzzle's retry middleware covers raw HTTP clients, and larger resilience libraries exist if you need circuit breakers or bulkheads. keboola/retry remains a good choice when you want one tiny, framework-independent wrapper around arbitrary PHP callables.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console