Guzzle in PHP: Common Questions Answered
Guzzle is a PHP HTTP client used to send requests and work with responses.
This guide answers the questions PHP developers most often ask when wiring Guzzle into a scraper or API client: how to authenticate, how to handle TLS verification, where the response body lives when a request throws, and how to send JSON or route traffic through a proxy.
What Guzzle is and is not
Guzzle is a third-party HTTP client for PHP, not part of the PHP standard library. You add it to a project through Composer. It is actively maintained; the question of whether it is deprecated comes up because older major versions have reached end of life, but the library itself continues to be developed. Under the hood Guzzle can use cURL as its transport handler, which is why cURL-related options and errors surface in Guzzle code.
Authentication: basic auth and authenticated proxies
For HTTP basic authentication, pass an auth array on the request options with the username and password. For a proxy that requires credentials, set the proxy option to a URL that includes the credentials, or pass them in the proxy configuration. Keep credentials out of source control and load them from environment variables or a secrets store.
SSL certificate errors
When a target presents a certificate that the local CA bundle cannot verify, Guzzle raises a connection exception. You can bypass verification by setting verify to false on the request options, but that removes protection against man-in-the-middle attacks and should be limited to controlled debugging. In production, point verify at a current CA bundle instead.
Exceptions, response bodies and client errors
By default Guzzle throws a RequestException for HTTP 4xx and 5xx responses. The response object is still attached to the exception, so you can read the status code and body from it rather than losing the payload. If you prefer to inspect every response yourself, set http_errors to false and check the status code on the returned response. Distinguish this from a connection failure, where no response exists at all.
Sending a JSON POST request
Use the json request option to have Guzzle serialize an array as a JSON body and set the Content-Type header to application/json. Do not also set a raw body option for the same request; pick one representation so the payload is not sent twice or malformed.
Quick decision checklist
Before you ship a Guzzle call, confirm: (1) credentials come from configuration, not literals; (2) verify is left on in production; (3) you know whether you want exceptions on 4xx/5xx or http_errors set to false; (4) you read the response body from the exception when one is thrown; (5) JSON payloads use the json option rather than a hand-built string; (6) proxy credentials are supplied through the proxy option, not appended to the target URL.
Frequently asked questions
How do I do HTTP basic authentication with Guzzle?
Pass an auth option on the request with the username and password. Guzzle encodes them and adds the Authorization header for you.
How do I ignore SSL certificate errors with Guzzle?
Set verify to false in the request options. This disables certificate checking and is only appropriate for controlled debugging; in production, point verify at a current CA bundle instead.
Does Guzzle use cURL?
Guzzle can use cURL as its transport handler. That is why cURL-related options and errors appear in Guzzle code.
How do I handle a Guzzle exception and get the HTTP body?
Catch the RequestException and read the response from it. The response object carries the status code and body, so the payload is not lost when the exception is thrown.
How do you handle client errors in Guzzle?
Either catch the RequestException and inspect the attached response, or set http_errors to false and check the status code on the returned response yourself.
How do I send a POST request in JSON with Guzzle?
Use the json request option with an array. Guzzle serializes it and sets the Content-Type header to application/json.
How do I use a proxy with authentication in Guzzle?
Set the proxy option to a URL that includes the credentials, or pass them in the proxy configuration. Keep credentials out of source control.
Is Guzzle a built-in PHP library?
No. Guzzle is a third-party package installed through Composer, not part of the PHP standard library.
Is PHP Guzzle deprecated?
Guzzle itself is actively maintained. Older major versions have reached end of life, which is why the question comes up, but the current library continues to be developed.
What is Guzzle used for in PHP?
Guzzle is used to send HTTP requests and work with responses in PHP applications, including scrapers, API clients and integrations that need authentication, JSON payloads or proxy routing.