{"id":15374320,"url":"https://github.com/yurunsoft/guzzle-swoole","last_synced_at":"2025-04-05T13:07:43.337Z","repository":{"id":56043423,"uuid":"143095204","full_name":"Yurunsoft/Guzzle-Swoole","owner":"Yurunsoft","description":"让基于 Guzzle 的项目完美无缝兼容 Swoole 协程，支持：Guzzle、Elasticsearch client——来自宇润 PHP 全家桶","archived":false,"fork":false,"pushed_at":"2022-01-10T08:47:44.000Z","size":88,"stargazers_count":158,"open_issues_count":2,"forks_count":21,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-29T12:07:52.116Z","etag":null,"topics":["coroutine","guzzle","guzzlehttp","php","swoole"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Yurunsoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-01T02:45:43.000Z","updated_at":"2025-03-01T19:04:22.000Z","dependencies_parsed_at":"2022-08-15T12:01:05.441Z","dependency_job_id":null,"html_url":"https://github.com/Yurunsoft/Guzzle-Swoole","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FGuzzle-Swoole","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FGuzzle-Swoole/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FGuzzle-Swoole/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Yurunsoft%2FGuzzle-Swoole/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Yurunsoft","download_url":"https://codeload.github.com/Yurunsoft/Guzzle-Swoole/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339158,"owners_count":20923014,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coroutine","guzzle","guzzlehttp","php","swoole"],"created_at":"2024-10-01T13:58:21.049Z","updated_at":"2025-04-05T13:07:43.320Z","avatar_url":"https://github.com/Yurunsoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Guzzle-Swoole\n\n[![Latest Version](https://img.shields.io/packagist/v/yurunsoft/guzzle-swoole.svg)](https://packagist.org/packages/yurunsoft/guzzle-swoole)\n[![Php Version](https://img.shields.io/badge/php-%3E=7.1-brightgreen.svg)](https://secure.php.net/)\n[![Swoole Version](https://img.shields.io/badge/swoole-%3E=4.0.0-brightgreen.svg)](https://github.com/swoole/swoole-src)\n[![IMI License](https://img.shields.io/github/license/Yurunsoft/Guzzle-Swoole.svg)](https://github.com/Yurunsoft/Guzzle-Swoole/blob/master/LICENSE)\n\n## 介绍\n\nguzzle-swoole 可以无损支持 Guzzle 在 Swoole 协程环境下的运行，不需要修改任何一行第三方包代码，即可支持协程化。\n\n支持 Guzzle v6.x、v7.x。\n\n支持 Composer v1.x、v2.x。\n\n可以用于 `ElasticSearch`、`AWS` 等 SDK 当中。\n\n兼容所有 Swoole 框架。\n\nQQ群：17916227 [![点击加群](https://pub.idqqimg.com/wpa/images/group.png \"点击加群\")](https://jq.qq.com/?_wv=1027\u0026k=5wXf4Zq)\n\n## 使用说明\n\n### 安装\n\n手动改 `composer.json`：`\"yurunsoft/guzzle-swoole\":\"^2.2\"`\n\n命令行安装：`composer require yurunsoft/guzzle-swoole`\n\n### 全局设定处理器\n\n```php\n\u003c?php\nrequire dirname(__DIR__) . '/vendor/autoload.php';\n\nuse GuzzleHttp\\Client;\nuse Yurun\\Util\\Swoole\\Guzzle\\SwooleHandler;\nuse GuzzleHttp\\DefaultHandler;\n\n// 在你的项目入口加上这句话\nDefaultHandler::setDefaultHandler(SwooleHandler::class);\n\ngo(function(){\n    $client = new Client();\n    $response = $client-\u003erequest('GET', 'http://www.baidu.com', [\n        'verify'    =\u003e  false,\n    ]);\n    var_dump($response-\u003egetStatusCode());\n});\n\n```\n\n### 手动指定 Swoole 处理器\n\n```php\nuse GuzzleHttp\\Client;\nuse GuzzleHttp\\HandlerStack;\nuse Yurun\\Util\\Swoole\\Guzzle\\SwooleHandler;\n\ngo(function(){\n    $handler = new SwooleHandler();\n    $stack = HandlerStack::create($handler);\n    $client = new Client(['handler' =\u003e $stack]);\n    $response = $client-\u003erequest('GET', 'http://www.baidu.com', [\n        'verify'    =\u003e  false,\n    ]);\n    var_dump($response-\u003egetBody()-\u003e__toString(), $response-\u003egetHeaders());\n});\n```\n\n更加详细的示例代码请看`test`目录下代码。\n\n### ElasticSearch\n\n```php\n$client = \\Elasticsearch\\ClientBuilder::create()-\u003esetHosts(['192.168.0.233:9200'])-\u003esetHandler(new \\Yurun\\Util\\Swoole\\Guzzle\\Ring\\SwooleHandler())-\u003ebuild();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurunsoft%2Fguzzle-swoole","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyurunsoft%2Fguzzle-swoole","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyurunsoft%2Fguzzle-swoole/lists"}