2017 © Pedro Peláez
 

library backoff

Simple PHP Backoff Library

image

nevsnode/backoff

Simple PHP Backoff Library

  • Wednesday, July 11, 2018
  • by nevsnode
  • Repository
  • 1 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 18 % Grown

The README.md

nevsnode/Backoff

Very simple Backoff PHP library. It provides an easy solution to wait after failures with an increasing delay., (*1)

Install

composer require nevsnode/backoff

Example Usage

<?php
use nevsnode\Backoff;

$backoff = new Backoff();

$resource = new ExampleResource();
$result = $backoff->retryOnException(5, function () use ($resource) {
    $return = $resource->fetchSomething();
    if (!$return) {
        throw new Exception('Failed to fetch something');
    }
    return $return;
});

By default, when exceeding the number of retries, the last exception will just be thrown again. Optionally a final closure/value can be defined which is executed or returned instead:, (*2)

<?php
$backoff = new nevsnode\Backoff();

// $result will now become the string "Some error"
$result = $backoff->retryOnException(3, function () {
    throw new \Exception('Some error');
}, function ($e) {
    return $e->getMessage();
});

// $result will now become FALSE
$result = $backoff->retryOnException(2, function () {
    throw new \Exception('Some error');
}, false);

Settings

Setting Type Default Description
min Integer 1000 Minimum delay (in ms)
max Integer 30000 Maximum delay (in ms)
factor Float 2.0 Multiplicator of delay on additional delays
jitter Boolean true Allow jitter
jitterMax Integer 2000 Maximum jitter (in ms)
exceptions List of Strings every Throwable/Exception Specific list of exception-classes which will be retried

The settings can be passed as an associative array to the constructor and returned or adjusted after instantiation:, (*3)

<?php

// pass settings to constructor
$backoff = new Backoff([
    'min' => 2000,
    'max' => 10000,
    'factor' => M_E,
]);

// define setting through setter
$backoff->setJitter(true);
$backoff->setJitterMax(6000);
$backoff->setMin(3000);

// return setting through getter
$max = $backoff->getMax();

The Versions

11/07 2018

dev-master

9999999-dev

Simple PHP Backoff Library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

11/07 2018

v1.3.0

1.3.0.0

Simple PHP Backoff Library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

06/07 2017

v1.2.0

1.2.0.0

Simple PHP Backoff Library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

01/07 2017

v1.1.0

1.1.0.0

Simple PHP Backoff Library

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

10/05 2016

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires