Guzzle Documentation
Guzzle is a PHP HTTP client that makes it easy to send HTTP requests andtrivial to integrate with web services.
- Simple interface for building query strings, POST requests, streaming largeuploads, 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 youto utilize other PSR-7 compatible libraries with Guzzle.
- Abstracts away the underlying HTTP transport, allowing you to writeenvironment and transport agnostic code; i.e., no hard dependency on cURL,PHP streams, sockets, or non-blocking event loops.
- Middleware system allows you to augment and compose client behavior.
- $client = new GuzzleHttp\Client();
- $res = $client->request('GET', 'https://api.github.com/user', [
- 'auth' => ['user', 'pass']
- ]);
- echo $res->getStatusCode();
- // "200"
- echo $res->getHeader('content-type')[0];
- // 'application/json; charset=utf8'
- echo $res->getBody();
- // {"type":"User"...'
- // 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();