All Projects → yriveiro → php-backoff

yriveiro / php-backoff

Licence: MIT license
Simple back off / retry functionality

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to php-backoff

backoff
PHP library providing retry functionality with multiple backoff strategies and jitter support
Stars: ✭ 132 (+450%)
Mutual labels:  jitter, retry, backoff
Backoff
Python library providing function decorators for configurable backoff and retry
Stars: ✭ 1,670 (+6858.33%)
Mutual labels:  retry, backoff
awsretry
Decorate your AWS Boto3 Calls with AWSRetry.backoff(). This will allows your calls to get around the AWS Eventual Consistency Errors.
Stars: ✭ 42 (+75%)
Mutual labels:  retry, backoff
retryx
Promise-based retry workflow library.
Stars: ✭ 21 (-12.5%)
Mutual labels:  retry, retry-library
waiter
Delayed iteration for polling and retries.
Stars: ✭ 17 (-29.17%)
Mutual labels:  retry, backoff
Tenacity
Retrying library for Python
Stars: ✭ 3,472 (+14366.67%)
Mutual labels:  retry, retry-library
Resty
Simple HTTP and REST client library for Go
Stars: ✭ 5,368 (+22266.67%)
Mutual labels:  retry, backoff
jest-retry
Jest retry pattern for flaky E2E tests
Stars: ✭ 36 (+50%)
Mutual labels:  retry, retry-library
Rehttp
Package rehttp implements a Go HTTP transport that handles retries.
Stars: ✭ 170 (+608.33%)
Mutual labels:  retry
jitternator
Lessons learnt from hunting jitter issues
Stars: ✭ 59 (+145.83%)
Mutual labels:  jitter
Safely
Safely is a Clojure's circuit-breaker library for handling retries in an elegant declarative way.
Stars: ✭ 152 (+533.33%)
Mutual labels:  retry
Resilient.js
Fault tolerant and reactive HTTP client for node.js and browsers
Stars: ✭ 172 (+616.67%)
Mutual labels:  retry
View Load Retry
这个加载框架有点不一样,针对View进行加载,加载页面还保持了原View的属性,侧重点在灵活,哪里需要加载哪里,加载状态页面完全自定义,无任何限制,针对加载结果可以按需配置对应页面,LeakCanary检测无内存泄漏
Stars: ✭ 119 (+395.83%)
Mutual labels:  retry
Kotlin Retry
A higher-order function for retrying operations that may fail.
Stars: ✭ 159 (+562.5%)
Mutual labels:  retry
retries
Forget about your retry boilerplate
Stars: ✭ 14 (-41.67%)
Mutual labels:  retry
Toolkit
Collection of useful patterns
Stars: ✭ 137 (+470.83%)
Mutual labels:  retry
request-on-steroids
An HTTP client ✨ with retry, circuit-breaker and tor support 📦 out-of-the-box
Stars: ✭ 19 (-20.83%)
Mutual labels:  retry
esa-httpclient
An asynchronous event-driven HTTP client based on netty.
Stars: ✭ 82 (+241.67%)
Mutual labels:  retry
Toxy
Hackable HTTP proxy for resiliency testing and simulated network conditions
Stars: ✭ 2,698 (+11141.67%)
Mutual labels:  retry
Mug
A small Java 8 util library, complementary to Guava (BiStream, Substring, MoreStreams, Parallelizer).
Stars: ✭ 236 (+883.33%)
Mutual labels:  retry

Backoff, Simple backoff / retry functionality

License Build Status Coverage Status Total Downloads SensioLabsInsight

NOTE: to use php-backoff with PHP 5.x please use the lastet release of branch 1.x

API

getDefaultOptions():

This method is static and returns an array with the default options:

  • cap: Max duration allowed (in microseconds). If backoff duration is greater than cap, cap is returned, default is 1000000 microseconds.
  • maxAttempts: Number of attempts before thrown an Yriveiro\Backoff\BackoffException. Default is 0, no limit.

exponential($attempt):

This method use and exponential function E(attempt) = (2**attempt - 1) to calculate backoff time.

Parameters

  • attempt: incremental value that represents the current retry number.

equalJitter($attempt);

Exponential backoff has one disadvantage. In high concurrence, we can have multiples calls with the same backoff time due the time is highly bound to the current attempt, different calls could be in the same attempt.

To solve this we can add a jitter value to allow some randomization.

equalJitter uses the function: E(attempt) = min(((2**attempt - 1) / 2), random(0, ((2**attempt - 1) / 2))).

Parameters

  • attempt: incremental value that represents the current retry number.

fullJitter($attempt);

Full jitter behaves like equalJitter method, the main difference between them is the way in how the jitter value is calculated.

fullJitter uses the function: E(attempt) = min(random(0, (2**attempt - 1) / 2)).

Parameters

  • attempt: incremental value that represents the current retry number.

Usage

Zero configuration examples:

With zero configuration, we will never stop to try fetch data. The exit condition is your responsibility.

$attempt = 1;
$backoff = new Backoff();

$response = $http->get('http://myservice.com/user/1');

while (!$response) {
    $time = $backoff->exponential($attempt);
    $attempt++;

    usleep($time);

    $response = $http->get('http://myservice.com/user/1');
}

With configuration examples:

$attempt = 1;
$options = Backoff::getDefaultOptions();
$options['maxAttempts'] = 3;

$backoff = new Backoff($options);

$response = $http->get('http://myservice.com/user/1');

try
    while (!$response) {
        $time = $backoff->fullJitter($attempt);
        $attempt++;

        usleep($time);

        $response = $http->get('http://myservice.com/user/1');
    }
} catch (Yriveiro\Backoff\BackoffException $e) {
    // Handle the exception
}

Installation

The recommended way to install this package is through Composer.

php composer.phar require "yriveiro/php-backoff"

Tests

Tests are performed using the phpunit library, to run them:

php vendor/bin/phpunit tests

Know issues

None.

How to contribute

Have an idea? Found a bug?, contributions are welcome :)

License

Backoff is licensed under MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].