定制 antelucangizmos/guzzle-retry-handler 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

antelucangizmos/guzzle-retry-handler

最新稳定版本:0.1.2

Composer 安装命令:

composer create-project antelucangizmos/guzzle-retry-handler

包简介

test guzzle client with retry support

README 文档

README

Shields Shields

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
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2024-06-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固