https://github.com/yurunsoft/guzzle-swoole
让基于 Guzzle 的项目完美无缝兼容 Swoole 协程,支持:Guzzle、Elasticsearch client——来自宇润 PHP 全家桶
https://github.com/yurunsoft/guzzle-swoole
coroutine guzzle guzzlehttp php swoole
Last synced: 25 days ago
JSON representation
让基于 Guzzle 的项目完美无缝兼容 Swoole 协程,支持:Guzzle、Elasticsearch client——来自宇润 PHP 全家桶
- Host: GitHub
- URL: https://github.com/yurunsoft/guzzle-swoole
- Owner: Yurunsoft
- License: mit
- Created: 2018-08-01T02:45:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-01-10T08:47:44.000Z (over 3 years ago)
- Last Synced: 2025-03-29T12:07:52.116Z (about 1 month ago)
- Topics: coroutine, guzzle, guzzlehttp, php, swoole
- Language: PHP
- Homepage:
- Size: 85.9 KB
- Stars: 158
- Watchers: 4
- Forks: 21
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Guzzle-Swoole
[](https://packagist.org/packages/yurunsoft/guzzle-swoole)
[](https://secure.php.net/)
[](https://github.com/swoole/swoole-src)
[](https://github.com/Yurunsoft/Guzzle-Swoole/blob/master/LICENSE)## 介绍
guzzle-swoole 可以无损支持 Guzzle 在 Swoole 协程环境下的运行,不需要修改任何一行第三方包代码,即可支持协程化。
支持 Guzzle v6.x、v7.x。
支持 Composer v1.x、v2.x。
可以用于 `ElasticSearch`、`AWS` 等 SDK 当中。
兼容所有 Swoole 框架。
QQ群:17916227 [](https://jq.qq.com/?_wv=1027&k=5wXf4Zq)
## 使用说明
### 安装
手动改 `composer.json`:`"yurunsoft/guzzle-swoole":"^2.2"`
命令行安装:`composer require yurunsoft/guzzle-swoole`
### 全局设定处理器
```php
request('GET', 'http://www.baidu.com', [
'verify' => false,
]);
var_dump($response->getStatusCode());
});```
### 手动指定 Swoole 处理器
```php
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
```php
$client = \Elasticsearch\ClientBuilder::create()->setHosts(['192.168.0.233:9200'])->setHandler(new \Yurun\Util\Swoole\Guzzle\Ring\SwooleHandler())->build();
```