HTTP Helper Classes

The Twilio Rest Client

class Services_Twilio

Create a client to talk to the Twilio Rest API.

  • $sid (string) – Your Account SID
  • $token (string) – Your Auth Token from your dashboard
  • $version (string) – API version to use
  • $_http (Services_Twilio_TinyHttp) – A HTTP client for making requests.
  • $retryAttempts (int) – Number of times to retry failed requests. Currently only idempotent requests (GET’s and DELETE’s) are retried.

Here’s an example:

$client = new Services_Twilio('AC123', '456bef', null, null, 3);
// Take some action with the client, etc.

Twilio’s Custom HTTP Client

class Services_Twilio_TinyHttp

An HTTP client that makes requests

  • $uri (string) – The base uri to use for requests
  • $kwargs (array) –

    An array of additional arguments to pass to the library. Accepted arguments are:

    • debug - Print the HTTP request before making it to Twilio
    • curlopts - An array of keys and values that are passed to

Here’s an example. This is the default HTTP client used by the library.

$_http = new Services_Twilio_TinyHttp(
    array("curlopts" => array(
        CURLOPT_HTTPHEADER => array('Accept-Charset: utf-8'),
        CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem',

Twilio Rest Exceptions

class Services_Twilio_RestException

An exception talking to the Twilio API. This is thrown whenever the Twilio API returns a 400 or 500-level exception.

  • $status (int) – the HTTP status for the exception
  • $message (string) – a human-readable error message for the exception
  • $code (int) – a Twilio-specific error code for the exception
  • $info (string) – a link to more information

Get the HTTP status code


Get a link to more information