PHPackages                             graze/transient-fault-handler - 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. graze/transient-fault-handler

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

graze/transient-fault-handler
=============================

Retry tasks that fail due to transient faults

0.3.1(6y ago)425.3k↓75%[1 issues](https://github.com/graze/transient-fault-handler/issues)1MITPHPPHP &gt;=5.5.0

Since Mar 2Pushed 6y ago12 watchersCompare

[ Source](https://github.com/graze/transient-fault-handler)[ Packagist](https://packagist.org/packages/graze/transient-fault-handler)[ Docs](https://github.com/graze/transient-fault-handler)[ RSS](/packages/graze-transient-fault-handler/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (5)Versions (6)Used By (1)

Transient Fault Handler
=======================

[](#transient-fault-handler)

[![Latest Version on Packagist](https://camo.githubusercontent.com/09dd9d48c32f44c0fab805703a688b0d5590806994cdf4f0384049636248aba0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6772617a652f7472616e7369656e742d6661756c742d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/transient-fault-handler)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/e5b5b47b075633e78297db3d493d0f79f6331b52d72f55178c61a338c73d48fe/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6772617a652f7472616e7369656e742d6661756c742d68616e646c65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/graze/transient-fault-handler)[![Coverage Status](https://camo.githubusercontent.com/269ff26c12095a43dfe9f9622c05218f30caae071f65537c3cf2b844d626e32f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6772617a652f7472616e7369656e742d6661756c742d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/transient-fault-handler/code-structure)[![Quality Score](https://camo.githubusercontent.com/2943612c724379489a6b0d3c2027e81b1b5fcf7e90ed08e9828b69ac904b3a37/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6772617a652f7472616e7369656e742d6661756c742d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/graze/transient-fault-handler)[![Total Downloads](https://camo.githubusercontent.com/3ea7bc34f40f00bc7583e2154147664f5a3c8d06e8b03cffe58ba7ddf618a991/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6772617a652f7472616e7369656e742d6661756c742d68616e646c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/graze/transient-fault-handler)

Retries tasks that fail due to transient errors. Well suited to network requests but can retry any callable.

Install
-------

[](#install)

Via Composer

```
composer require graze/transient-fault-handler
```

Usage
-----

[](#usage)

The transient fault handler takes two detection strategies and a retry strategy. The builder can be used to quickly create a handler.

```
$task = function () {
    // Task that is prone to transient errors
};

$builder = new TransientFaultHandlerBuilder();
$transientFaultHandler = $builder->build();

$result = $transientFaultHandler->execute($task);
```

### Detection Strategy

[](#detection-strategy)

When a task is tried, it will either return some value or throw an exception.

The detection strategies will decide if that value/exception indicates a transient error or not.

If it does, then the fault handler will be told to retry the task. if it does not, then the value/exception either indicates a success or a non-transient error that retrying wouldn't solve.

In these cases, the value is returned to the caller or the exception is rethrown.

- `FalseyReturnValueDetectionStrategy`: treats return values that [evaluate to false](http://php.net/manual/en/types.comparisons.php) as transient.
- `StaticDetectionStrategy`: returns a static value set when constructing the strategy, regardless of the return value or exception.

### Retry Strategy

[](#retry-strategy)

If the detection strategy decides that the task should be retried, the retry strategy will decide how long to wait before doing so (the backoff period), and optionally impose a maximum number of retries on the task.

- `ExponentialBackoffStrategy`: the backoff period is chosen randomly between zero and an exponentially increasing maximum.

### Builder

[](#builder)

The builder makes it easier to create a fault handler by automatically injecting dependencies. The default strategies that the builder uses can be overridden by using the setters.

```
$builder = new TransientFaultHandlerBuilder();
$transientFaultHandler = $builder
    ->setExceptionDetectionStrategy(new StaticDetectionStrategy())
    ->setReturnValueDetectionStrategy(new FalseyReturnValueDetectionStrategy())
    ->setRetryStrategy(new ExponentialBackoffStrategy())
    ->setLogger(new Logger())
    ->build();
```

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
make test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Jake Wright](https://github.com/jakewright)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 54.5% 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 ~406 days

Total

4

Last Release

2191d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/637788?v=4)[graze.com](/maintainers/graze)[@graze](https://github.com/graze)

---

Top Contributors

[![biggianteye](https://avatars.githubusercontent.com/u/1482649?v=4)](https://github.com/biggianteye "biggianteye (6 commits)")[![jakewright](https://avatars.githubusercontent.com/u/5333300?v=4)](https://github.com/jakewright "jakewright (5 commits)")

---

Tags

retrynetworkinggrazetransient fault

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/graze-transient-fault-handler/health.svg)

```
[![Health](https://phpackages.com/badges/graze-transient-fault-handler/health.svg)](https://phpackages.com/packages/graze-transient-fault-handler)
```

###  Alternatives

[symfony/lock

Creates and manages locks, a mechanism to provide exclusive access to a shared resource

514139.2M692](/packages/symfony-lock)[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k53](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.2M209](/packages/illuminate-broadcasting)[logiscape/mcp-sdk-php

Model Context Protocol SDK for PHP

368116.8k12](/packages/logiscape-mcp-sdk-php)

PHPackages © 2026

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