Twilio PHP Library Using A Proxy
Updated 2026-09-26: reworked for current twilio-php.
Back in 2013 this meant patching a CURLOPT_PROXY line into the library’s TinyHttp.php, and I asked for a proxy option in twilio-php#144. Current twilio-php’s CurlClient takes an array of curl options, so put the proxy there and pass the client to Client as its fifth argument:
<?php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Http\CurlClient;
use Twilio\Rest\Client;
$httpClient = new CurlClient([
CURLOPT_PROXY => 'http://192.0.2.10:8080',
CURLOPT_SUPPRESS_CONNECT_HEADERS => true,
]);
$twilio = new Client($sid, $token, null, null, $httpClient);
CURLOPT_SUPPRESS_CONNECT_HEADERS keeps the proxy’s reply to CONNECT out of the response. CurlClient only strips that reply when it’s a bare status line, so a proxy that adds headers to it, like tinyproxy, breaks response parsing without the option.