作者:mobiledu2502858787 | 来源:互联网 | 2023-01-30 10:13
介绍
让 Guzzle 支持 Swoole 协程,这个项目目的就是这么简单明了!
Guzzle-Swoole 是 Guzzle 的处理器(Handler),并没有对 Guzzle 本身代码进行修改,理论上可以兼容后续版本。
v2.0.0 更新日志
* 新增 Ring Handler 支持,可以用于 elasticsearch/elasticsearch 等包中:
* 无需再手动引入 guzzle
* 使用 YurunHttp 作为 Http 请求驱动,更加稳定可靠
使用说明
Composer:"yurunsoft/guzzle-swoole":"~2.0"
全局设定处理器
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();
码云:https://gitee.com/yurunsoft/Guzzle-Swoole
Github:https://github.com/Yurunsoft/Guzzle-Swoole