2011-11-13 19:28:24 -06:00
|
|
|
Guzzle, PHP HTTP client and webservice framework
|
2012-01-14 13:57:05 -06:00
|
|
|
================================================
|
2011-11-11 17:21:41 -06:00
|
|
|
|
2014-03-02 10:45:13 -08:00
|
|
|
[![Build Status](https://secure.travis-ci.org/guzzle/guzzle.png?branch=master)](http://travis-ci.org/guzzle/guzzle)
|
2013-06-10 13:47:53 -07:00
|
|
|
|
2014-03-02 10:45:13 -08:00
|
|
|
Guzzle is a PHP HTTP client that makes it easy to work with HTTP/1.1 and takes
|
|
|
|
the pain out of consuming web services.
|
2013-06-03 23:12:35 -07:00
|
|
|
|
|
|
|
```php
|
2014-03-02 10:45:13 -08:00
|
|
|
$client = new GuzzleHttp\Client();
|
|
|
|
$response = $client->get('http://guzzlephp.org');
|
|
|
|
$res = $client->get('https://api.github.com/user', ['auth' => ['user', 'pass']]);
|
|
|
|
echo $res->statusCode();
|
|
|
|
// 200
|
|
|
|
echo $res->getHeader('content-type');
|
|
|
|
// 'application/json; charset=utf8'
|
|
|
|
echo $res->getBody();
|
|
|
|
// {"type":"User"...'
|
|
|
|
var_export($res->json());
|
|
|
|
// Outputs the JSON decoded data
|
2013-06-03 23:12:35 -07:00
|
|
|
```
|
2011-11-13 19:28:24 -06:00
|
|
|
|
2014-03-02 10:45:13 -08:00
|
|
|
- Pluggable HTTP adapters that can send requests serially or in parallel
|
|
|
|
- Doesn't require cURL, but uses cURL by default
|
|
|
|
- Streams data for both uploads and downloads
|
|
|
|
- Provides event hooks & plugins for cookies, caching, logging, OAuth, mocks,
|
|
|
|
etc...
|
|
|
|
- Keep-Alive & connection pooling
|
|
|
|
- SSL Verification
|
|
|
|
- Automatic decompression of response bodies
|
|
|
|
- Streaming multipart file uploads
|
|
|
|
- Connection timeouts
|
|
|
|
|
|
|
|
Get more information and answers with the
|
|
|
|
[Documentation](http://guzzlephp.org/),
|
|
|
|
[Forums](https://groups.google.com/forum/?hl=en#!forum/guzzle),
|
|
|
|
and IRC ([#guzzlephp](irc://irc.freenode.net/#guzzlephp) @ irc.freenode.net).
|
|
|
|
|
2012-06-17 17:59:53 -07:00
|
|
|
### Installing via Composer
|
|
|
|
|
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
|
|
|
```
|
|
|
|
|
|
|
|
Next, update your project's composer.json file to include Guzzle:
|
2012-06-17 17:59:53 -07:00
|
|
|
|
2014-03-15 16:46:57 -07:00
|
|
|
```javascript
|
|
|
|
{
|
|
|
|
{
|
|
|
|
"require": {
|
|
|
|
"guzzlehttp/guzzle": "4.0.0-rc.1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2014-03-02 10:45:13 -08:00
|
|
|
### Documentation
|
2013-06-30 11:21:03 +01:00
|
|
|
|
2014-03-02 10:45:13 -08:00
|
|
|
More information can be found in the online documentation at
|
|
|
|
http://guzzlephp.org/.
|