PHP code example of tagadvance / elephant-retrying

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

    

tagadvance / elephant-retrying example snippets


$retryer = RetryerBuilder::newBuilder()
	->retryIfResult('is_null')
	->retryIfExceptionOfType(\RuntimeException::class)
	->withStopStrategy(StopStrategies . stopAfterAttempt(3))
	->build();
try {
	$retryer->call(fn() => true); // do something useful here
} catch (RetryException $e) {
	print $e->getTraceAsString();
} catch (ExecutionException $e) {
	print $e->getTraceAsString();
}

$maximumWaitTimeSeconds = 300; // 5 minutes
$retryer = RetryerBuilder::newBuilder()
        ->retryIfExceptionOfType(\RuntimeException::class)
        ->withWaitStrategy(WaitStrategies::exponentialWait(1, $maximumWaitTimeSeconds))
        ->withStopStrategy(StopStrategies::neverStop())
        ->build();

$maximumWaitTimeSeconds = 120; // 2 minutes
$retryer = RetryerBuilder::newBuilder()
	->retryIfExceptionOfType(\RuntimeException::class)
	->withWaitStrategy(WaitStrategies::fibonacciWait(1, $maximumWaitTimeSeconds))
	->withStopStrategy(StopStrategies::neverStop())
	->build();