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

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

gohany/retry
============

Common interface for retrying operations

v1.0.5(7mo ago)05671MITPHPPHP &gt;=7.1

Since Sep 19Pushed 7mo agoCompare

[ Source](https://github.com/Gohany/Retry)[ Packagist](https://packagist.org/packages/gohany/retry)[ Docs](https://github.com/Gohany/Retry)[ RSS](/packages/gohany-retry/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (6)DependenciesVersions (7)Used By (1)

Retry Interfaces &amp; RTRY Policy (Draft)
==========================================

[](#retry-interfaces--rtry-policy-draft)

A tiny set of PHP interfaces for standardized retry behavior, plus a compact `rtry:` string you can store in one column and compile at runtime.

Features
--------

[](#features)

- **Portable API**: `RetryerInterface::try(callable $op, RetryPolicyInterface $policy, array $context = [])`.
- **Single‑column policy** with `rtry:` strings (backoff, jitter, deadlines, hedging hints).
- **Testable**: `ClockInterface` + `SleeperInterface` → no real sleeps in unit tests.
- **Deciders**: pluggable logic to map outcomes to retry/stop decisions.

Quick start
-----------

[](#quick-start)

```
use Psr\Retry\Impl\RtryPolicyFactory;
use Psr\Retry\Impl\RtryPolicy;
use foreup\rest\models\services\Retry;
use foreup\rest\models\services\NativeSleeper;
use Psr\Clock\ClockInterface;

// Construct runtime pieces (DI in real apps)
$factory = new RtryPolicyFactory();
$policy = $factory->fromSpec('rtry:a=5;d=250ms;mode=exp;b=2;cap=5s;jmode=full;on=5xx,ETIMEDOUT');

$retryer = new Retry($clock /* PSR-20 */, new NativeSleeper());

$response = $retryer->try(function ($ctx) use ($httpClient, $request) {
    $res = $httpClient->sendRequest($request);
    if ($res->getStatusCode() >= 500) {
        throw new RuntimeException('server_error');
    }
    return $res;
}, $policy, ['tenant_id' => 12345, 'correlation_id' => 'req-abc123']);
```

Interfaces (overview)
---------------------

[](#interfaces-overview)

- `RetryerInterface` — runs the callable under a policy.
- `RetryPolicyInterface` — attempts, delays, jitter, deadlines, hedging hints, decider.
- `RetryPolicyFactoryInterface` — parses `rtry:` into a policy.
- `AttemptContextInterface` — attempt #, elapsed, remaining budget, context.
- `AttemptOutcomeInterface` — result or error for deciders.
- `JitterSpecInterface` — deterministic jitter application.
- `RetryDeciderInterface` — retry/stop decision.

See **SPEC.md** for normative details and the full RTRY grammar.

Testing
-------

[](#testing)

Provide a test `SleeperInterface` that records sleep calls instead of actually sleeping, and a fixed `ClockInterface` (PSR‑20) for deterministic timing.

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

[](#contributing)

1. Open issues/PRs here to refine the draft.
2. If there’s interest, we’ll form a **Working Group** and seek a **Sponsor** inside PHP‑FIG.

License
-------

[](#license)

- **Code** (interfaces, reference impl): MIT
- **Spec/docs** (SPEC.md, this README): **CC‑BY 4.0**

### Attribution/NOTICE

[](#attributionnotice)

> © 2025 Gregory Riley and contributors. Licensed under Creative Commons Attribution 4.0 (CC BY 4.0). Changes may have been made. License:

Reference implementation (non-normative)
----------------------------------------

[](#reference-implementation-non-normative)

A production-ready reference implementation lives here:

- Repo:
- Packagist: gohany/rtry (MIT)

This implementation is provided to demonstrate how the interfaces and the `rtry:` policy can be used in practice. It is **non-normative** and does not change the meaning of this spec.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance63

Regular maintenance activity

Popularity18

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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

Total

6

Last Release

232d ago

### Community

Maintainers

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

---

Tags

retry

### Embed Badge

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

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

###  Alternatives

[vkartaviy/retry

The library for repeatable and retryable operations

29227.2k2](/packages/vkartaviy-retry)[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.

16396.8k](/packages/tobion-retry)[yriveiro/php-backoff

Simple backoff / retry functionality

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

PHPackages © 2026

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