antelucangizmos/guzzle-retry-handler
最新稳定版本:0.1.2
Composer 安装命令:
composer create-project antelucangizmos/guzzle-retry-handler
包简介
test guzzle client with retry support
README 文档
README
APIs might implement rate limiting, and if they do your clients might experience 429 Too Many Requests responses with a Retry-After header, informing your client how long it should wait before making the next request.
Guzzle includes a retry middleware class that can be used to handle this.
The implementation in this project is a PoC, so feel free to build upon it, and comment if you think something should be added / removed.
Example usage
require dirname(__DIR__, 2) . '/vendor/autoload.php'; use Ag\Guzzle\Handler\Retry; use GuzzleHttp\Client; use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Handler\CurlHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Middleware; class TestRetry { public function test(int $maxRetries = 5) { $handlerStack = HandlerStack::create(new CurlHandler()); $retry = new Retry($maxRetries); $handlerStack->push(Middleware::retry($retry->retryDecider(), $retry->retryDelay())); $client = new Client(array('handler' => $handlerStack)); $response = $client->request( 'GET', // @ToDo replace to a real url!!! 'https://some-url-here' )->getBody()->getContents(); return print_r($response, true); } } try { $TestRetry = new TestRetry(); $response = $TestRetry->test(5); echo $response . PHP_EOL; } catch (ConnectException $e) { echo $e->getMessage() . PHP_EOL; }
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2024-06-19