PHPackages                             georgii-web/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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. georgii-web/retry

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

georgii-web/retry
=================

A PHP package to wrap any piece of code with a retry algorithm.

v1.0.1(10mo ago)12.5k↓74.7%MITPHPPHP &gt;=8.2CI failing

Since Jun 22Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/GeorgII-web/Retry)[ Packagist](https://packagist.org/packages/georgii-web/retry)[ RSS](/packages/georgii-web-retry/feed)WikiDiscussions master Synced 2d ago

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

Retry
=====

[](#retry)

A PHP package to wrap any piece of code with a retry algorithm. It provides a simple and flexible way to handle transient failures in your code by automatically retrying operations that fail due to exceptions.

[![Latest Version on Packagist](https://camo.githubusercontent.com/7810f41af7a1863ee9b676e417f8f7190fb8706265ceae38c148829fd7ef9fe1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f67656f726769692d7765622f72657472792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/georgii-web/retry)[![Tests](https://github.com/georgii-web/retry/actions/workflows/php.yml/badge.svg)](https://github.com/georgii-web/retry/actions/workflows/php.yml)[![Total Downloads](https://camo.githubusercontent.com/6da18061955e697b14a88edf7f879e1da936ad71e12d9227496cc7c655a3c3dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f67656f726769692d7765622f72657472792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/georgii-web/retry)

Requirements
------------

[](#requirements)

- PHP 8.2 or higher

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

[](#installation)

You can install the package via composer:

```
composer require georgii-web/retry
```

Basic Usage
-----------

[](#basic-usage)

The most basic way to use the package is to retry a piece of code a specific number of times:

```
use GeorgII\Retry;

// Retry a function 3 times on any exception
$result = Retry::onAnyException(fn() => someOperation());
```

Some possible options:

```
use GeorgII\Retry;
use GeorgII\RetryEvent;

// Retry a function 2 times, with a small delay and logging events on any exception
$result = Retry::onAnyException(
    attemptCallback: function (RetryEvent $event) {
        // Your code that might fail
       return someOperation($event);
    },
    retryCount: 2,
    retryDelay: 0.1,
    eventCallback: function (RetryEvent $event) {
        var_dump($event->getName());
    }
);
```

**Warning:** Only temporary exceptions should be retried. It is not meaningful to retry exceptions such as `Throwable`, validation exceptions, or any other issues that are unlikely to be resolved on subsequent attempts. Retrying should be reserved for transient errors, such as connection issues, where a retry has a realistic chance of succeeding.

Custom aliases
--------------

[](#custom-aliases)

To simplify the definition of specific retry logic, you can utilize an alias. If the default retry logic is not sufficient for your needs, define your own in the project (e.g., specifying delays and exceptions to retry), wrap it in an alias, and use it in a straightforward manner.

```
    /**
     * Retry on DB exception alias.
     *
     * @template R
     *
     * @param Closure(RetryEvent): R          $attemptCallback
     * @param positive-int|null               $retryCount
     * @param positive-int|float|Closure|null $retryDelay
     * @param Closure(RetryEvent):void|null   $eventCallback
     *
     * @return R
     */
    public static function onDbException(
        Closure $attemptCallback,
        ?int $retryCount = null,
        int|float|Closure|null $retryDelay = null,
        ?Closure $eventCallback = null,
    ): mixed {
        $retry = new RetryCore();

        return $retry
            ->setRetryExceptions([
                ConnectionLost::class,
            ])
            ->setEventCallback($eventCallback)
            ->setRetryCount($retryCount)
            ->setRetryDelay($retryDelay)
            ->setEventFactory(new RetryEventFactory($retry))
            ->setCheckExactException(false)
            ->handle($attemptCallback);
    }
```

Alias usage:

```
$users = Retry::onDbException(fn() => $sql->query('SELECT * from users'));
```

Documentation
-------------

[](#documentation)

For detailed usage examples and API reference, please see the [Documentation](DOCUMENTATION.md).

Development
-----------

[](#development)

For information on setting up the development environment and contributing to the project, please see the [Development Guide](DEVELOPMENT.md).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance54

Moderate activity, may be stable

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

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 ~59 days

Total

2

Last Release

318d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8732fb5579944b880eba4d8f719cb9d97cf3c2d2cfafa4c7562c1c0850eeeb96?d=identicon)[GeorgII](/maintainers/GeorgII)

---

Top Contributors

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

---

Tags

algorithmerror-handlingpackageresilienceretryretryAlgorithmerror handlingresilience

###  Code Quality

TestsPest

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[yannelli/attempt

A fluent attempt/retry/fallback system for Laravel

481.0k](/packages/yannelli-attempt)

PHPackages © 2026

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