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.
- 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
$client = new GuzzleHttp\Client();$res = $client->get('https://api.github.com/user', [ 'auth' => ['user', 'pass']]);echo $res->getStatusCode(); // 200echo $res->getHeader('content-type'); // 'application/json; charset=utf8'echo $res->getBody(); // {"type":"User"...'var_export($res->json()); // Outputs the JSON decoded data
User guide
HTTP Components
There are a number of optional libraries you can use along with Guzzle's HTTP layer to add capabilities to the client.
- Logs HTTP requests and responses sent over the wire using customizable log message templates.
- Signs requests using OAuth 1.0.
- Emits progress events when uploading and downloading data.
- Implements a private transparent proxy cache that caches HTTP responses.
- Retries failed requests using customizable retry strategies (e.g., retry based on response status code, cURL error codes, etc...)
- Verifies the message integrity of HTTP responses using customizable validators. This plugin can be used, for example, to verify the Content-MD5 headers of responses.
Service Description Commands
You can use the Guzzle Command library to encapsulate interaction with a web service using command objects. Building on top of Guzzle's command abstraction allows you to easily implement things like service description that can be used to serialize requests and parse responses using a meta-description of a web service.
- Provides the foundational elements used to build high-level, command based, web service clients with Guzzle.
- Provides an implementation of the Guzzle Command library that uses Guzzle service descriptions to describe web services, serialize requests, and parse responses into easy to use model structures.