Jerry's WIKIJerry's WIKI
Overview
  • ๐Ÿž Web
  • ๐Ÿ“ Components
  • ๐Ÿ’ก Skills
  • ๐ŸŽฑ Specification
  • ๐Ÿ–ฅ Workflows
  • ๐Ÿ›  Tools
  • ๐ŸŒ๏ธ Linux
  • ๐Ÿ“ฆ Container
  • โ™จ๏ธ Language
Coffee
  • ็ฎ€ไฝ“ไธญๆ–‡
  • English
GitHub
Overview
  • ๐Ÿž Web
  • ๐Ÿ“ Components
  • ๐Ÿ’ก Skills
  • ๐ŸŽฑ Specification
  • ๐Ÿ–ฅ Workflows
  • ๐Ÿ›  Tools
  • ๐ŸŒ๏ธ Linux
  • ๐Ÿ“ฆ Container
  • โ™จ๏ธ Language
Coffee
  • ็ฎ€ไฝ“ไธญๆ–‡
  • English
GitHub
  • ๐Ÿ“ž Event Mechanism

    • Event Roles and Considerations
    • Code Example
  • โฐ Crontab
  • โ›“ Processes
  • ๐Ÿ“ File System
  • ๐Ÿ•“ Cache
  • ๐Ÿ“ฉ Queue

    • Queue Usage
    • Notes
  • ๐Ÿšฆ Signal
  • ๐Ÿ“ค GuzzleHttp
  • ๐Ÿ“‰ Rate Limiter
  • โŒ Exception
  • ๐Ÿ–จ Logs
  • ๐Ÿ“ก Command
  • ๐Ÿ” WebSocket

GuzzleHttp

Index

  • Install Dependencies
  • Encapsulation Of Utility Class.

ใ€Tipใ€‘

Usage of the coroutine-based GuzzleHttp client
For detailed usage, please refer to๏ผšGuzzleHttp Doc

Install Dependencies

Standard Library Address

composer require hyperf/guzzle

Encapsulation Of Utility Class.

<?php

declare(strict_types=1);

namespace App\Lib\GuzzleHttp;

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Hyperf\Guzzle\PoolHandler;
use Hyperf\Guzzle\RetryMiddleware;

use function Hyperf\Support\make;

class GuzzleFactory
{
    /**
     * ่Žทๅ–ๅธฆๆœ‰่ฟžๆŽฅๆฑ ็š„ๅ็จ‹็š„guzzleๅฎขๆˆท็ซฏ.
     * @explain make ไปŽdiไธญ่Žทๅ–ๅ•ไพ‹.
     * @see https://docs.guzzlephp.org/en/stable/
     * @param array $options ้€‰้กน
     * @return Client ๅฎขๆˆท็ซฏ
     */
    public static function getCoroutineGuzzleClient(array $options = []): Client
    {
        [$handler, $retry, $config] = [
            make(PoolHandler::class, ['option' => ['max_connections' => 50]]),
            make(RetryMiddleware::class, ['retries' => 1, 'delay' => 10]),
            [],
        ];
        $stack = HandlerStack::create($handler);
        $stack->push($retry->getMiddleware(), 'retry');

        $config['handler'] = $options['handler'] ?? $stack;
        $config = array_merge($config, $options);
        return make(Client::class, ['config' => $config]);
    }
}

Edit this page
Update At:
Contributor: ็”ฐๆœๅธ†
Prev
Signal
Next
Rate Limiter