PHPackages                             tobion/retry - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tobion/retry

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tobion/retry
============

A generic library to retry an operation in case of an error. You can configure the behavior like the exceptions to retry on.

v1.1.0(3mo ago)16480.3k↓21%1[1 PRs](https://github.com/Tobion/retry/pulls)MITPHPPHP &gt;=8.2CI passing

Since Sep 19Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/Tobion/retry)[ Packagist](https://packagist.org/packages/tobion/retry)[ Docs](https://github.com/Tobion/retry)[ RSS](/packages/tobion-retry/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Retry
=====

[](#retry)

PHP library for retrying code, e.g. HTTP requests or database transactions, in case of failures.

Installation
------------

[](#installation)

```
$ composer require tobion/retry

```

Usage
-----

[](#usage)

```
use Tobion\Retry\Retry;

$callableThatMightFail = function (int $arg1, int $arg2): int {
    if (random_int(1, 2) % 2) {
        throw new \RuntimeException('Sudden error');
    }

    return $arg1 + $arg2;
};

// Allows you to call the callable with parameters and retry its execution in case an exception is thrown.
// You can access the return value of the callable (3 in this case).
$returnValue = Retry::configure()->call($callableThatMightFail, 1, 2);

// By default:
// - The callable is retried twice (i.e. max three executions). If it still fails, the last error is rethrown.
// - Retries have a no delay between them.
// - Every \Throwable will trigger the retry logic, i.e. both \Exception and \Error.
// You can adjust the retry logic like this:
$retryingCallable = Retry::configure()
    ->maxRetries(5)
    ->delayInMs(100)
    ->retryOnSpecificExceptions(\RuntimeException::class) // other failures like \TypeError will not be retried
    ->decorate($callableThatMightFail)
;
$returnValue = $retryingCallable(1, 2);
// $retryingCallable just decorates the original callable and can be used like it.
// To find out how often it had to retry, you can use:
$retryingCallable->getRetries();
```

Contributing
------------

[](#contributing)

To run tests:

```
$ composer install
$ vendor/bin/simple-phpunit

```

###  Health Score

57

—

FairBetter than 98% of packages

Maintenance78

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 92.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2362 days

Total

2

Last Release

117d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.1

v1.1.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/d10b19f74fa2f712a4fbb9d9073c95d612c0f32e6ba95aed6f68e589c8e2688e?d=identicon)[Tobion](/maintainers/Tobion)

---

Top Contributors

[![Tobion](https://avatars.githubusercontent.com/u/610090?v=4)](https://github.com/Tobion "Tobion (36 commits)")[![cs278](https://avatars.githubusercontent.com/u/17377?v=4)](https://github.com/cs278 "cs278 (2 commits)")[![ChristianRiesen](https://avatars.githubusercontent.com/u/1446701?v=4)](https://github.com/ChristianRiesen "ChristianRiesen (1 commits)")

---

Tags

delayexception-handlingphprestartretry-libraryretryrepeatrestartretryable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tobion-retry/health.svg)

```
[![Health](https://phpackages.com/badges/tobion-retry/health.svg)](https://phpackages.com/packages/tobion-retry)
```

###  Alternatives

[tplaner/when

Date/Calendar recursion library.

5331.1M7](/packages/tplaner-when)[vkartaviy/retry

The library for repeatable and retryable operations

29231.3k2](/packages/vkartaviy-retry)[eventsauce/backoff

Back-off strategy interface

70848.9k8](/packages/eventsauce-backoff)[mvo/contao-group-widget

Adds a new group widget that allows repeating a set of DCA fields.

26139.9k44](/packages/mvo-contao-group-widget)[yriveiro/php-backoff

Simple backoff / retry functionality

2780.9k1](/packages/yriveiro-php-backoff)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
