Score
0
Watch 3 Star 18 Fork 3

宇润 / Guzzle-SwoolePHPMIT

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
让基于 Guzzle 的项目完美无缝兼容 Swoole 协程 spread retract

https://github.com/Yurunsoft/Guzzle-Swoole

Clone or download
Loading...
README.md

Guzzle-Swoole

Latest Version Php Version Swoole Version IMI License

介绍

让 Guzzle 支持 Swoole 协程,这个项目目的就是这么简单明了!

Guzzle-Swoole 是 Guzzle 的处理器(Handler),并没有对 Guzzle 本身代码进行修改,理论上可以兼容后续版本。

QQ群:17916227 点击加群

使用说明

Composer:"yurunsoft/guzzle-swoole":"~1.1"

本项目不包含 Guzzle 功能,请自行在项目中引用 Guzzle 6.x,理论上可以支持升级 Guzzle 版本而无需更新 Guzzle-Swoole!

全局设定处理器

<?php
require dirname(__DIR__) . '/vendor/autoload.php';

use GuzzleHttp\Client;
use Yurun\Util\Swoole\Guzzle\SwooleHandler;
use GuzzleHttp\DefaultHandler;

DefaultHandler::setDefaultHandler(SwooleHandler::class);

go(function(){
    $client = new Client();
    $response = $client->request('GET', 'http://www.baidu.com', [
        'verify'    =>  false,
    ]);
    var_dump($response->getStatusCode());
});

手动指定 Swoole 处理器

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use Yurun\Util\Swoole\Guzzle\SwooleHandler;

go(function(){
    $handler = new SwooleHandler();
    $stack = HandlerStack::create($handler);
    $client = new Client(['handler' => $stack]);
    $response = $client->request('GET', 'http://www.baidu.com', [
        'verify'    =>  false,
    ]);
    var_dump($response->getBody()->__toString(), $response->getHeaders());
});

更加详细的示例代码请看test目录下代码。

Comments ( 0 )

Sign in for post a comment

PHP
1
https://gitee.com/yurunsoft/Guzzle-Swoole.git
git@gitee.com:yurunsoft/Guzzle-Swoole.git
yurunsoft
Guzzle-Swoole
Guzzle-Swoole
master

Help Search