stayforlong/finite-guzzlehttp

支持有限超时的 Guzzle HTTP 客户端

v0.1.0 2019-11-11 13:04 UTC

This package is auto-updated.

Last update: 2024-09-12 00:08:50 UTC


README

HTTP 客户端,允许请求具有有限超时,以避免无限等待(Guzzle 不支持)。

安装

通过 Composer 安装最新版本

$ composer require stayforlong/finite-guzzlehttp:0.1.0

用法

使用依赖注入来自动加载 Guzzle,它在底层使用

<?php

use StayForLong\FiniteGuzzleHTTP\Client;

class MyClient {
    private $finiteClient;

    public function __construct(Client $client) {
        $this->finiteClient = $client;
    }

    public function finiteGet($unstableEndpoint) {
        $this->finiteClient->get($unstableEndpoint);
    }
}

// ...

try {
    $myClient->finiteGet(UNSTABLE_ENDPOINT);
} catch (ConnectException $e) {
    // do not let your requests wait forever
}