内容简介:Guzzle 是一个非常流行的 PHP 的 HTTP 客户端,现在各大厂的 SDK 也都开始基于 Guzzle 开发,因为 Swoole 只支持 PHP Stream 的协程 Hook ,而 Guzzle 默认是使用 cURL 扩展的,所以使用 Composer 安装:在项目的
Guzzle 是一个非常流行的 PHP 的 HTTP 客户端,现在各大厂的 SDK 也都开始基于 Guzzle 开发,因为 Swoole 只支持 PHP Stream 的协程 Hook ,而 Guzzle 默认是使用 cURL 扩展的,所以 Mix PHP 开发了 Guzzle Hook,能在不修改源码的情况下让 Guzzle 协程化。
Github
安装
使用 Composer 安装:
composer require mix/guzzle-hook
在项目的 composer.json
文件中增加 extra
配置项,如下:
"extra": {
"include_files": [
"vendor/mix/guzzle-hook/src/functions_include.php"
]
}
使用
直接使用 Guzzle 开发
无需做任何特殊的代码处理,直接根据 Guzzle 文档使用:
go(function () {
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/user', [
'auth' => ['user', 'pass'],
]);
echo $res->getStatusCode();
});
第三方 SDK 依赖 Guzzle
比如:
这类第三方库从 composer.json 的 require 能看出来依赖了 guzzlehttp/guzzle,则可以在 Swoole 的协程中直接使用。
go(function () {
try {
// 实例化一个证书对象,入参需要传入腾讯云账户secretId,secretKey
$cred = new Credential("secretId", "secretKey");
// # 实例化要请求产品(以cvm为例)的client对象
$client = new CvmClient($cred, "ap-guangzhou");
// 实例化一个请求对象
$req = new DescribeZonesRequest();
// 通过client对象调用想要访问的接口,需要传入请求对象
$resp = $client->DescribeZones($req);
print_r($resp->toJsonString());
} catch (TencentCloudSDKException $e) {
echo $e;
}
});
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 生态系统支持计划:2020第一季度总结
- PouchContainer 0.3.0 支持 Kubernetes 拥抱 CNCF 生态
- Hadoop生态组件Yarn之长期运行服务支持篇!
- Flutter 2.2 发布:针对各平台的性能优化、完善生态支持
- Apache SkyWalking APM 生态衍生多语言监控, 支持 .NET Core
- 阿里云100%核心产品支持IPv6,两年内完成阿里IPv6生态建设
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Developing Large Web Applications
Kyle Loudon / Yahoo Press / 2010-3-15 / USD 34.99
As web applications grow, so do the challenges. These applications need to live up to demanding performance requirements, and be reliable around the clock every day of the year. And they need to withs......一起来看看 《Developing Large Web Applications》 这本书的介绍吧!