PHP code example of yriveiro / php-backoff

1. Go to this page and download the library: Download yriveiro/php-backoff library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yriveiro / php-backoff example snippets


$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');
}

$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
}
sh
php composer.phar 
sh
php vendor/bin/phpunit tests