PHPackages                             diephp/perhaps - 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. diephp/perhaps

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

diephp/perhaps
==============

Catch and Retry Code Execution

v1.0.4(2mo ago)11.4kMITPHPPHP ^7.4 || ^8.0

Since May 24Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/diephp/perhaps)[ Packagist](https://packagist.org/packages/diephp/perhaps)[ RSS](/packages/diephp-perhaps/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (6)Versions (6)Used By (0)

[![Total Downloads](https://camo.githubusercontent.com/f30cd7f8ddcca0ccf347a97dfd81a1100497ad44550ef49068fdfc06eaa76a1c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6469657068702f70657268617073)](https://packagist.org/packages/diephp/perhaps)[![Latest Stable Version](https://camo.githubusercontent.com/ca17e6985f15c35d0a89ee6ab7c95601a86089002d1b6faf9f2c3b28c9d55b6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6469657068702f70657268617073)](https://packagist.org/packages/diephp/perhaps)[![License](https://camo.githubusercontent.com/306e9a338cf9d5503fe3a34aa11930bb881792851483342a3b1a1ba7bb3d3a3a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6469657068702f70657268617073)](https://packagist.org/packages/diephp/perhaps)

Perhaps Retry Library
=====================

[](#perhaps-retry-library)

Perhaps is a retry library for Laravel `9` to `13` and for plain PHP projects without Laravel.

It helps you safely repeat operations that may fail temporarily: HTTP requests, external API calls, synchronization tasks, background jobs, cron processes, connections, and other unstable integrations. Instead of failing immediately, you can retry the same action several times and control the delay between attempts.

Why use this package
--------------------

[](#why-use-this-package)

The main advantage of `diephp/perhaps` is support for a `Traversable` delay sequence.

That means you are not limited to a single fixed delay between retries. You can pass a sequence where every next retry uses its own interval. This is especially useful when working with external services that may:

- respond with temporary errors;
- become unavailable for a short time;
- recover gradually after overload;
- require a softer backoff strategy instead of aggressive repeated requests.

With `delaySequence` you can describe growing retry intervals using mathematical sequences such as logarithmic, progressive, exponential, random, or any custom iterator that implements `Traversable`.

This can be more flexible than Laravel's built-in retry helper when you need a fully described retry schedule instead of one repeated delay value.

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

[](#installation)

Install the package with Composer:

```
composer require diephp/perhaps
```

Laravel Installation
--------------------

[](#laravel-installation)

### Laravel 9-11

[](#laravel-9-11)

Register the service provider in `config/app.php`:

```
'providers' => [
    // ...
    DiePHP\Perhaps\Providers\PerhapsServiceProvider::class,
],
```

### Laravel v12, v13+

[](#laravel-v12-v13)

Register the provider in `bootstrap/providers.php`:

```
