webclient/ext-retry

PSR-18 HTTP 客户端的重试扩展

v1.0.1 2022-07-22 14:50 UTC

This package is not auto-updated.

Last update: 2024-09-14 00:42:19 UTC


README

Latest Stable Version Total Downloads License PHP

webclient/ext-retry

PSR-18 HTTP 客户端的重试扩展。

安装

安装此包以及您喜欢的 psr-18 实现

composer require webclient/ext-retry:^1.0

使用

<?php

use Webclient\Extension\Retry\RetryClientDecorator;
use \Webclient\Extension\Retry\Timer\Timer;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;

/** 
 * @var ClientInterface $client Your PSR-18 HTTP Client
 * @var Timer $timer Timer implements
 * @var int $maxAttempts Max attempts
 */
$http = new RetryClientDecorator($client, $timer, $maxAttempts);

/** @var RequestInterface $request */
$response = $http->sendRequest($request);