Guzzle Documentation
Guzzle is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services.
- 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.
- Middleware system allows you to augment and compose client behavior.
1. $client = new GuzzleHttp\Client();
2. $res = $client->request('GET', 'https://api.github.com/user', [
3. 'auth' => ['user', 'pass']
4. ]);
5. echo $res->getStatusCode();
6. // "200"
7. echo $res->getHeader('content-type');
8. // 'application/json; charset=utf8'
9. echo $res->getBody();
10. // {"type":"User"...'
12. // Send an asynchronous request.
13. $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');
14. $promise = $client->sendAsync($request)->then(function ($response) {
15. echo 'I completed! ' . $response->getBody();
16. });
17. $promise->wait();
User Guide
- Overview
- Requirements
- Installation
- License
- Contributing
- Reporting a security vulnerability
- Quickstart
- Making a Request
- Using Responses
- Query String Parameters
- Uploading Data
- Cookies
- Redirects
- Exceptions
- Environment Variables
- Request Options
- allow_redirects
- auth
- body
- cert
- cookies
- connect_timeout
- debug
- decode_content
- delay
- expect
- force_ip_resolve
- form_params
- headers
- http_errors
- json
- multipart
- on_headers
- on_stats
- progress
- proxy
- query
- read_timeout
- sink
- ssl_key
- stream
- synchronous
- verify
- timeout
- version
- Guzzle and PSR-7
- Headers
- Body
- Requests
- Responses
- Streams
- Handlers and Middleware
- Handlers
- Middleware
- HandlerStack
- Creating a Handler
- Testing Guzzle Clients
- Mock Handler
- History Middleware
- Test Web Server
- FAQ
- Does Guzzle require cURL?
- Can Guzzle send asynchronous requests?
- How can I add custom cURL options?
- How can I add custom stream context options?
- Why am I getting an SSL verification error?
- What is this Maximum function nesting error?
- Why am I getting a 417 error response?
- How can I track redirected requests?
