2015-03-28 15:36:00 -07:00
|
|
|
Guzzle, PHP HTTP client
|
|
|
|
=======================
|
2011-11-11 17:21:41 -06:00
|
|
|
|
2018-03-26 13:42:22 +02:00
|
|
|
[![Latest Version](https://img.shields.io/github/release/guzzle/guzzle.svg?style=flat-square)](https://github.com/guzzle/guzzle/releases)
|
|
|
|
[![Build Status](https://img.shields.io/travis/guzzle/guzzle.svg?style=flat-square)](https://travis-ci.org/guzzle/guzzle)
|
|
|
|
[![Total Downloads](https://img.shields.io/packagist/dt/guzzlehttp/guzzle.svg?style=flat-square)](https://packagist.org/packages/guzzlehttp/guzzle)
|
2013-06-10 13:47:53 -07:00
|
|
|
|
2014-10-09 23:04:32 -07:00
|
|
|
Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and
|
|
|
|
trivial to integrate with web services.
|
2014-10-08 18:35:23 -07:00
|
|
|
|
2015-03-29 11:10:33 -07:00
|
|
|
- Simple interface for building query strings, POST requests, streaming large
|
|
|
|
uploads, streaming large downloads, using HTTP cookies, uploading JSON data,
|
|
|
|
etc...
|
|
|
|
- Can send both synchronous and asynchronous requests using the same interface.
|
|
|
|
- Uses PSR-7 interfaces for requests, responses, and streams. This allows you
|
|
|
|
to utilize other PSR-7 compatible libraries with Guzzle.
|
|
|
|
- Abstracts away the underlying HTTP transport, allowing you to write
|
|
|
|
environment and transport agnostic code; i.e., no hard dependency on cURL,
|
|
|
|
PHP streams, sockets, or non-blocking event loops.
|
2015-03-29 12:34:54 -07:00
|
|
|
- Middleware system allows you to augment and compose client behavior.
|
2013-06-03 23:12:35 -07:00
|
|
|
|
|
|
|
```php
|
2016-07-01 11:23:17 +02:00
|
|
|
$client = new \GuzzleHttp\Client();
|
2019-01-14 09:56:56 -05:00
|
|
|
$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle');
|
2019-01-08 15:57:56 -05:00
|
|
|
|
2019-01-14 09:56:56 -05:00
|
|
|
echo $response->getStatusCode(); # 200
|
|
|
|
echo $response->getHeaderLine('content-type'); # 'application/json; charset=utf8'
|
|
|
|
echo $response->getBody(); # '{"id": 1420053, "name": "guzzle", ...}'
|
2019-01-08 15:57:56 -05:00
|
|
|
|
|
|
|
# Send an asynchronous request.
|
2015-03-28 15:36:00 -07:00
|
|
|
$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
|
2015-05-28 09:03:15 +01:00
|
|
|
$promise = $client->sendAsync($request)->then(function ($response) {
|
2015-06-30 09:15:07 -07:00
|
|
|
echo 'I completed! ' . $response->getBody();
|
2014-10-08 18:35:23 -07:00
|
|
|
});
|
2019-01-08 15:57:56 -05:00
|
|
|
|
2015-03-28 15:36:00 -07:00
|
|
|
$promise->wait();
|
2013-06-03 23:12:35 -07:00
|
|
|
```
|
2011-11-13 19:28:24 -06:00
|
|
|
|
2015-03-29 11:10:33 -07:00
|
|
|
## Help and docs
|
2014-03-02 10:45:13 -08:00
|
|
|
|
2015-03-29 11:10:33 -07:00
|
|
|
- [Documentation](http://guzzlephp.org/)
|
2017-03-07 22:04:28 +03:00
|
|
|
- [Stack Overflow](http://stackoverflow.com/questions/tagged/guzzle)
|
2015-03-29 11:10:33 -07:00
|
|
|
- [Gitter](https://gitter.im/guzzle/guzzle)
|
2014-03-02 10:45:13 -08:00
|
|
|
|
2015-03-28 15:36:00 -07:00
|
|
|
|
2015-03-29 11:10:33 -07:00
|
|
|
## Installing Guzzle
|
2012-06-17 17:59:53 -07:00
|
|
|
|
2014-03-02 10:45:13 -08:00
|
|
|
The recommended way to install Guzzle is through
|
|
|
|
[Composer](http://getcomposer.org).
|
2012-06-17 17:59:53 -07:00
|
|
|
|
2013-06-03 23:12:35 -07:00
|
|
|
```bash
|
|
|
|
# Install Composer
|
2013-06-04 00:29:54 -06:00
|
|
|
curl -sS https://getcomposer.org/installer | php
|
2014-03-15 16:46:57 -07:00
|
|
|
```
|
|
|
|
|
2014-10-13 15:57:22 -04:00
|
|
|
Next, run the Composer command to install the latest stable version of Guzzle:
|
2012-06-17 17:59:53 -07:00
|
|
|
|
2014-10-13 15:57:22 -04:00
|
|
|
```bash
|
2019-07-31 13:16:45 +04:30
|
|
|
composer require guzzlehttp/guzzle
|
2013-06-03 23:12:35 -07:00
|
|
|
```
|
2012-06-26 17:32:25 -07:00
|
|
|
|
2013-06-03 23:12:35 -07:00
|
|
|
After installing, you need to require Composer's autoloader:
|
2012-06-26 17:32:25 -07:00
|
|
|
|
2013-06-03 23:12:35 -07:00
|
|
|
```php
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
```
|
2012-06-26 17:32:25 -07:00
|
|
|
|
2015-03-29 11:10:33 -07:00
|
|
|
You can then later update Guzzle using composer:
|
2013-06-30 11:21:03 +01:00
|
|
|
|
2015-03-29 11:10:33 -07:00
|
|
|
```bash
|
2019-07-31 13:16:45 +04:30
|
|
|
composer update
|
2015-03-29 11:10:33 -07:00
|
|
|
```
|
2015-05-26 11:22:06 -07:00
|
|
|
|
|
|
|
|
|
|
|
## Version Guidance
|
|
|
|
|
2016-11-15 10:37:24 +01:00
|
|
|
| Version | Status | Packagist | Namespace | Repo | Docs | PSR-7 | PHP Version |
|
|
|
|
|---------|------------|---------------------|--------------|---------------------|---------------------|-------|-------------|
|
|
|
|
| 3.x | EOL | `guzzle/guzzle` | `Guzzle` | [v3][guzzle-3-repo] | [v3][guzzle-3-docs] | No | >= 5.3.3 |
|
2016-11-15 11:43:43 +01:00
|
|
|
| 4.x | EOL | `guzzlehttp/guzzle` | `GuzzleHttp` | [v4][guzzle-4-repo] | N/A | No | >= 5.4 |
|
2019-10-30 11:58:00 +02:00
|
|
|
| 5.x | EOL | `guzzlehttp/guzzle` | `GuzzleHttp` | [v5][guzzle-5-repo] | [v5][guzzle-5-docs] | No | >= 5.4 |
|
2019-12-08 14:23:48 +01:00
|
|
|
| 6.x | Maintained | `guzzlehttp/guzzle` | `GuzzleHttp` | [v6][guzzle-6-repo] | [v6][guzzle-6-docs] | Yes | >= 5.5 |
|
|
|
|
| 7.x | Latest | `guzzlehttp/guzzle` | `GuzzleHttp` | [v7][guzzle-7-repo] | [v7][guzzle-7-docs] | Yes | >= 7.2 |
|
2015-05-26 20:17:25 -07:00
|
|
|
|
2015-05-26 20:22:21 -07:00
|
|
|
[guzzle-3-repo]: https://github.com/guzzle/guzzle3
|
2016-11-15 10:37:24 +01:00
|
|
|
[guzzle-4-repo]: https://github.com/guzzle/guzzle/tree/4.x
|
2015-05-26 20:21:48 -07:00
|
|
|
[guzzle-5-repo]: https://github.com/guzzle/guzzle/tree/5.3
|
2019-12-08 16:13:22 +01:00
|
|
|
[guzzle-6-repo]: https://github.com/guzzle/guzzle/tree/6.5
|
2019-12-08 14:23:48 +01:00
|
|
|
[guzzle-7-repo]: https://github.com/guzzle/guzzle
|
2018-06-25 13:32:10 +02:00
|
|
|
[guzzle-3-docs]: http://guzzle3.readthedocs.org
|
2019-12-08 16:13:22 +01:00
|
|
|
[guzzle-5-docs]: http://docs.guzzlephp.org/en/5.3/
|
|
|
|
[guzzle-6-docs]: http://docs.guzzlephp.org/en/6.5/
|
|
|
|
[guzzle-7-docs]: http://docs.guzzlephp.org/en/latest/
|