Twilio Client PHP Quickstart

Let's walk through making our first phone call from your browser to Twilio with Twilio Client.

Hello Monkey Client

Copy the following code into the hello-client-monkey.php file on your web server, substituting your own Account SID and Auth Token for the ones in the accountSid and authToken lines.

Let's say your server's domain is Assuming you put the PHP file in the document root, the URL will be: Load that URL in your browser -- it will display a button that will initiate an audio connection into Twilio when clicked. The first few lines of code generates a secure Capability Token that Twilio Client uses to authorize the connection (using your account credentials).

We also registered two Twilio Client callbacks:

  1. ready - callback for when the client is successfully registered with Twilio.
  2. error - callback for when an error happens, such as a connection error.
    include 'Services/Twilio/Capability.php';

    // put your Twilio API credentials here
    $accountSid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $authToken  = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy';

    $capability = new Services_Twilio_Capability($accountSid, $authToken);
    $token = $capability->generateToken();

    <!DOCTYPE html>
        <title>Hello Client Monkey 1</title>
        <script type="text/javascript"
        <script type="text/javascript"
        <link href="//"
          type="text/css" rel="stylesheet" />
        <script type="text/javascript">

          Twilio.Device.setup("<?php echo $token; ?>");

          Twilio.Device.ready(function (device) {

          Twilio.Device.error(function (error) {
            $("#log").text("Error: " + error.message);

          Twilio.Device.connect(function (conn) {
            $("#log").text("Successfully established call");

          function call() {
        <button class="call" onclick="call();">

        <div id="log">Loading pigeons...</div>

You are now ready to make the call, so go ahead and click the 'Call' button! Did you hear the welcome message? Cool!

But hey, how do you close the connection and hangup the call? Keep reading...

Next: Hanging Up Calls »