poor-plebs / guzzle-retry-after-middleware
一个 guzzle 中间件,用于跟踪 Retry-After HTTP 头部,并在指定时间之前失败连续请求。
3.0.1
2022-12-18 14:31 UTC
Requires
- php: ^8.1.0
- guzzlehttp/guzzle: ^6.5.8 || ^7.4.5
- guzzlehttp/promises: ^1.0.0
- nesbot/carbon: ^2.62.1
- psr/http-message: ^1.0.0
- psr/simple-cache: ^1.0.0 || ^2.0.0 || ^3.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13.0
- illuminate/cache: ^9.38.0
- phpstan/phpstan: ^1.9.0
- phpunit/phpunit: ^9.5.26
- roave/security-advisories: dev-latest
- dev-main
- 3.0.1
- 3.0.0
- 2.1.0
- 2.0.0
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- dev-dependabot/composer/illuminate/cache-10.21.0
- dev-dependabot/composer/friendsofphp/php-cs-fixer-3.25.1
- dev-dependabot/composer/phpstan/phpstan-1.10.32
- dev-dependabot/composer/phpunit/phpunit-10.3.2
- dev-dependabot/composer/guzzlehttp/promises-2.0.1
- dev-release/3.0.1
- dev-release/3.0.0
This package is auto-updated.
Last update: 2024-09-04 04:25:14 UTC
README
用途是什么? | 要求是什么? | 如何安装? | 如何使用? | 如何贡献?
一个 guzzle 中间件,用于跟踪 Retry-After HTTP 头部,并在指定时间之前失败连续请求。
用途是什么?
一些 HTTP 服务器可能会响应一个 Retry-After
头部,提示客户端何时重新向服务器发送请求。原因可能多种多样,没有严格的使用该头部的场景。通常,它与响应状态码 429 Too Many Requests
一起使用进行速率限制,或者与 503 Service Unavailable
一起使用,表示依赖项离线或服务器处于维护状态。在这两种情况下,服务器会提示客户端何时重试请求,以避免在当前时间点无法处理请求对服务器造成的压力。在某些情况下,如果客户端不尊重此回退请求,服务器可能会以某种形式阻止或禁止客户端。
为了避免这种情况,您可以使用专为 guzzle http 客户端制作的中间件。根据中间件文档,您可以跟踪 Retry-After 头部的回退期间,以便在此期间发出的请求将因一个特定的异常而失败。
要求是什么?
- PHP 8.0 或更高版本
如何安装?
composer require poor-plebs/guzzle-retry-after-middleware
如何使用?
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. }
如何贡献?
poor-plebs/guzzle-retry-after-middleware
遵循语义版本控制。有关更多信息,请参阅 semver.org。
创建问题来报告问题或请求。通过分支和创建拉取请求来提出解决方案和想法。始终在未发布部分添加 CHANGELOG.md 条目。