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

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

jralph/retry
============

A simple library to retry things.

3.0.0(2y ago)985.5k2MITPHPPHP ^8.0

Since Oct 5Pushed 2y agoCompare

[ Source](https://github.com/jralph/retry)[ Packagist](https://packagist.org/packages/jralph/retry)[ RSS](/packages/jralph-retry/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (14)Used By (0)

PHP Retry [![Latest Stable Version](https://camo.githubusercontent.com/46c6b5e1134b7e6ab6f9b5baa6e577052f9c249a9a886c3f2dcda1f699c30980/68747470733a2f2f706f7365722e707567782e6f72672f6a72616c70682f72657472792f762f737461626c65)](https://packagist.org/packages/jralph/retry) [![Total Downloads](https://camo.githubusercontent.com/a3eb10e9803743eb8158ddfb5f146703e3c6537a863d4167664be9b8aa416967/68747470733a2f2f706f7365722e707567782e6f72672f6a72616c70682f72657472792f646f776e6c6f6164732e737667)](https://packagist.org/packages/jralph/retry) [![Latest Unstable Version](https://camo.githubusercontent.com/ef5e0dce4114dc05dbec19d1603b063d7fa2f434bcfebf24134dcddea122ef8d/68747470733a2f2f706f7365722e707567782e6f72672f6a72616c70682f72657472792f762f756e737461626c652e737667)](https://packagist.org/packages/jralph/retry) [![License](https://camo.githubusercontent.com/815ca2c11f28e756256fb106473ad3188b4c7adb926041d74174efd9011e7440/68747470733a2f2f706f7365722e707567782e6f72672f6a72616c70682f72657472792f6c6963656e73652e737667)](https://packagist.org/packages/jralph/retry)
===========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-retry----)

A simple library to retry commands in php.

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

[](#installation)

This package is available through composer.

```
composer require jralph/retry

```

Basic Use
---------

[](#basic-use)

The library includes a simple helper function for ease of use.

*Note: On a failure to succeed in running the command, a `Jralph\Retry\RetryException` will be thrown.*

```
mixed retry (int|callable $attempts , callable $command [, callable $onError = null])
```

### Parameters

[](#parameters)

- `$attempts:` The number of times to attempt a command.
    - If a `callable` is provided, the retry will continue until this closure returns true.
- `$command:` The command to run each time.
- `$onError:` An optional callback to run each time the `$command` fails.

### Example

[](#example)

```
