Corporate proxy
Route HTTPS through a corporate proxy via cURL options. Honours HTTP_PROXY / NO_PROXY environment variables when nothing is supplied explicitly.
CurlHttpClient exposes the extraCurlOptions constructor argument
for anything cURL can do — including proxies.
Use the environment variables
cURL honours HTTPS_PROXY (and NO_PROXY) by default. If your shell
exports them, no PHP-level change is needed:
export HTTPS_PROXY=http://proxy.corp.example:8080
export NO_PROXY=internal.corp.example
Set the proxy in code
new CurlHttpClient(
verifyTls: true,
extraCurlOptions: [
CURLOPT_PROXY => 'http://proxy.corp.example:8080',
CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
],
);
Authenticated proxy
new CurlHttpClient(
verifyTls: true,
extraCurlOptions: [
CURLOPT_PROXY => 'http://proxy.corp.example:8080',
CURLOPT_PROXYUSERPWD => 'username:password',
],
);
For NTLM, add CURLOPT_PROXYAUTH => CURLAUTH_NTLM (the runtime needs
cURL with NTLM compiled in).
SOCKS5
new CurlHttpClient(
extraCurlOptions: [
CURLOPT_PROXY => 'socks5h://proxy.corp.example:1080',
],
);
socks5h:// resolves DNS through the proxy — usually what you want
behind restrictive firewalls.
Bypass the proxy for specific hosts
new CurlHttpClient(
extraCurlOptions: [
CURLOPT_PROXY => 'http://proxy.corp.example:8080',
CURLOPT_NOPROXY => 'localhost,127.0.0.1,*.internal.corp.example',
],
);