I needed the --haproxy-protocol option from the curl
library to call the request. Within curl this option works great. But how to achieve the same in the PHP library Guzzle?
First, we needed to verify that the option exists in the library itself. As of PHP version 7.3, there is a constant CURLOPT_HAPROXYPROTOCOL that does the same thing. The call then looks like this:
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HAPROXYPROTOCOL, true);
// ...
The second question was how to use this option within the Guzzle library. While documentation does not describe the option, it is possible to set the curl
configuration. The library deliberately does not show this setting because it breaks the abstraction that Guzzle provides.
The whole call then looks like this
$client->request('GET', $url, [
'curl' => [CURLOPT_HAPROXYPROTOCOL => true],
]);
Other options can be added to the curl
field, as described in the PHP documentation for the curl_setopt function.
Top comments (0)