PHP code example of poor-plebs / guzzle-retry-after-middleware

1. Go to this page and download the library: Download poor-plebs/guzzle-retry-after-middleware 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/ */

    

poor-plebs / guzzle-retry-after-middleware example snippets



use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use PoorPlebs\GuzzleRetryAfterMiddleware\RetryAfterException;

/* Any implementation of the PSR-16 (simple cache) interface. In case of using
 * this package with Laravel, it could look something like:
 */
$cache = Cache::store('array');

$handlerStack = HandlerStack::create();

// Where to put this middleware in the middleware stack depends on the usecase.
$handlerStack->unshift(
    new RetryAfterMiddleware($cache),
    'retry_after', // Name of the middlewere for debugging purposes.
);

$client = new Client([
    'base_uri' => 'https://sometest.com/',
    'handler' => $handlerStack,
    // Can be set/overwritten on per request basis as well.
    RetryAfterMiddleware::REQUEST_OPTION => 'cache_key_to_use',
]);

try {
    $client->postAsync('sendMessage')->wait();
} catch (RetryAfterException $exception) {
    // Do something when the library blocks requests.
}