PHPackages                             netlogix/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. netlogix/retry

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

netlogix/retry
==============

Retries a specific PHP code fragment.

1.1.0(1mo ago)1152.0k↑45%1MITPHPPHP &gt;=8.1CI passing

Since Aug 5Pushed 1mo agoCompare

[ Source](https://github.com/netlogix/retry)[ Packagist](https://packagist.org/packages/netlogix/retry)[ RSS](/packages/netlogix-retry/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (1)

Netlogix Retry
==============

[](#netlogix-retry)

Retries a specific PHP code fragment (called a "task") as long as the "when" condition evaluates to `true`.

```
(new \Netlogix\Retry\Retry())
    ->when(condition: fn(int $incarnation) => $incarnation < PHP_INT_MAX)
    ->task(subject: fn () => throw new \RuntimeException('false'));
```

There is a shorthand method for counting retries and sleeping between attempts with increasing intervals.

```
(new \Netlogix\Retry\Retry())
    /**
     * http://backoffcalculator.com/?attempts=5&rate=1&interval=0.5
     * = (0.5 + 1 + 1.5 + 2.0 + 2.5) seconds
     * = 7.5 seconds
     */
    ->withExponentialBackoff(retryInterval: 0.5, maxRetries: 5)
    ->onExceptionsOfType(\Doctrine\DBAL\Exception\DeadlockException::class)
    ->task(fn () => $dbal->executeQuery($statement));
```

Reacting to errors
------------------

[](#reacting-to-errors)

The `onError` handler is invoked for **every** caught throwable, even for those the retry does not react to. It receives the throwable, a flag telling whether the throwable is one of the configured types to retry on, and the current incarnation (retry count). This is the place to forward exceptions to a logger or, for example, the Neos/Flow `ThrowableStorageInterface`.

```
(new \Netlogix\Retry\Retry())
    ->withExponentialBackoff(retryInterval: 0.5, maxRetries: 5)
    ->onExceptionsOfType(\Doctrine\DBAL\Exception\DeadlockException::class)
    ->onError(function (\Throwable $throwable, bool $shouldConsider, int $incarnation) use ($throwableStorage) {
        $throwableStorage->logThrowable($throwable);
    })
    ->task(fn () => $dbal->executeQuery($statement));
```

Returning `false` from the `onError` handler aborts retrying immediately and rethrows the throwable — the same "throw through" behaviour as an exhausted retry limit or a throwable of a type the retry does not react to. Returning anything else (including nothing) lets the normal retry logic proceed.

```
->onError(function (\Throwable $throwable) use ($throwableStorage) {
    $throwableStorage->logThrowable($throwable);

    if ($throwable instanceof \Some\Fatal\Exception) {
        return false; // stop retrying, rethrow immediately
    }
})
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance90

Actively maintained with recent releases

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~332 days

Total

2

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/667b5107f4c2ea180baa00166c2ee3f2a1b412ce22768d6e81bb09323d1c7fe0?d=identicon)[netlogix](/maintainers/netlogix)

![](https://avatars.githubusercontent.com/u/1595908?v=4)[Stephan Schuler](/maintainers/stephanschuler)[@stephanschuler](https://github.com/stephanschuler)

---

Top Contributors

[![stephanschuler](https://avatars.githubusercontent.com/u/1595908?v=4)](https://github.com/stephanschuler "stephanschuler (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[kdyby/datetime-provider

Time provider, providing consistent current date, time, datetime and timezone across the request.

1146.9k2](/packages/kdyby-datetime-provider)[uccellolabs/filament-theme-color

Easy way to change filament theme color on the fly.

1717.0k](/packages/uccellolabs-filament-theme-color)

PHPackages © 2026

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