3 Star 30 Fork 3

宇润 / Guzzle-Swoole

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Guzzle-Swoole

Latest Version Php Version Swoole Version IMI License

介绍

guzzle-swoole 可以无损支持 Guzzle 在 Swoole 协程环境下的运行,不需要修改任何一行第三方包代码,即可支持协程化。

支持 Guzzle v6.x、v7.x。

支持 Composer v1.x、v2.x。

可以用于 ElasticSearchAWS 等 SDK 当中。

兼容所有 Swoole 框架。

QQ群:17916227 点击加群

使用说明

安装

手动改 composer.json"yurunsoft/guzzle-swoole":"^2.2"

命令行安装:composer require yurunsoft/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目录下代码。

ElasticSearch

$client = \Elasticsearch\ClientBuilder::create()->setHosts(['192.168.0.233:9200'])->setHandler(new \Yurun\Util\Swoole\Guzzle\Ring\SwooleHandler())->build();
The MIT License (MIT) Copyright (c) 2018 宇润 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

让基于 Guzzle 的项目完美无缝兼容 Swoole 协程 展开 收起
PHP 等 3 种语言
MIT
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/yurunsoft/Guzzle-Swoole.git
git@gitee.com:yurunsoft/Guzzle-Swoole.git
yurunsoft
Guzzle-Swoole
Guzzle-Swoole
master

搜索帮助