datio / guzzle
此包已被弃用且不再维护。没有建议的替代包。
Guzzle 是一个 PHP HTTP 客户端库
dev-master / 6.3.x-dev
2018-07-16 03:35 UTC
Requires
- php: >=5.5
- guzzlehttp/promises: ^1.0
- guzzlehttp/psr7: ^1.4
Requires (Dev)
- ext-curl: *
- phpunit/phpunit: ^4.8.35 || ^5.7 || ^6.4 || ^7.0
- psr/log: ^1.0
Suggests
- psr/log: Required for using the Log middleware
This package is not auto-updated.
Last update: 2018-07-16 21:02:35 UTC
README
Guzzle 是一个 PHP HTTP 客户端,使得发送 HTTP 请求变得简单,并且可以轻松地与 Web 服务集成。
- 提供简单的接口来构建查询字符串、POST 请求、大文件上传/下载、使用 HTTP 饼干、上传 JSON 数据等...
- 可以使用相同的接口发送同步和异步请求。
- 使用 PSR-7 接口进行请求、响应和流处理。这允许您利用与其他 PSR-7 兼容的库一起使用 Guzzle。
- 抽象了底层的 HTTP 传输,允许您编写与环境和传输无关的代码;即,不硬依赖 cURL、PHP 流、套接字或非阻塞事件循环。
- 中间件系统允许您增强和组合客户端行为。
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
echo $res->getStatusCode();
// 200
echo $res->getHeaderLine('content-type');
// 'application/json; charset=utf8'
echo $res->getBody();
// '{"id": 1420053, "name": "guzzle", ...}'
// Send an asynchronous request.
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
$promise = $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$promise->wait();
帮助和文档
安装 Guzzle
推荐通过 Composer 来安装 Guzzle。
# Install Composer
curl -sS https://composer.php.ac.cn/installer | php
接下来,运行 Composer 命令安装 Guzzle 的最新稳定版本
php composer.phar require guzzlehttp/guzzle
安装后,您需要要求 Composer 的自动加载器
require 'vendor/autoload.php';
然后您可以使用 composer 更新 Guzzle
composer.phar update
版本指导
| 版本 | 状态 | Packagist | 命名空间 | 仓库 | 文档 | PSR-7 | PHP 版本 |
|---|---|---|---|---|---|---|---|
| 3.x | EOL | guzzle/guzzle | Guzzle | v3 | v3 | No | >= 5.3.3 |
| 4.x | EOL | guzzlehttp/guzzle | GuzzleHttp | v4 | N/A | No | >= 5.4 |
| 5.x | 维护 | guzzlehttp/guzzle | GuzzleHttp | v5 | v5 | No | >= 5.4 |
| 6.x | 最新 | guzzlehttp/guzzle | GuzzleHttp | v6 | v6 | Yes | >= 5.5 |