PHP code example of keboola / retry

1. Go to this page and download the library: Download keboola/retry 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/ */

    

keboola / retry example snippets




use Retry\RetryProxy;
use Retry\Policy\SimpleRetryPolicy;
use Retry\BackOff\ExponentialBackOffPolicy;

$retryPolicy = new SimpleRetryPolicy(3);
$backOffPolicy = new ExponentialBackOffPolicy();

$proxy = new RetryProxy($retryPolicy, $backOffPolicy);
$result = $proxy->call(function() {
    // call external service and return result
});



use Retry\RetryProxy;
use Retry\Policy\SimpleRetryPolicy;
use Retry\BackOff\ExponentialBackOffPolicy;

$retryPolicy = new CallableRetryPolicy(function (\Throwable $e) {
    if ($e->getCode() === 200) {
        return false;
    } 
    return true;
});
$proxy = new RetryProxy($retryPolicy, new ExponentialBackOffPolicy());
$result = $proxy->call(function() {
   // call external service and return result
});