Get Started

Twilio Client PHP Quickstart

Setting Up an Application

Wondering what actually happens when you connect to Twilio Client using your browser, and why you keep hearing that same welcome message? The key to this mystery is in this line:

$capability->allowClientOutgoing('APabe7650f654fc34655fc81ae71caa3ff');

This creates a security token that tells the browser which Twilio Application it will connect to. Applications are just references to TwiML URLs that are fetched when a connection is established from the browser. (If you are not familar with TwiML, we suggest you head over to the Twilio Markup Language Quickstart.)

So the string starting with 'AP' is an ApplicationSid. The default one above is a demo app created by Twilio that serves up a very simple TwiML document that uses to read a greeting.

Let’s build a simple application in PHP to serve TwiML from your web host. Create a new file called hello-client-monkey-twiml.php on your server and copy-paste the following code into that file:

Assuming your web server is at companyfoo.com, try loading up your new PHP script: http://companyfoo.com/hello-client-monkey-twiml.php in your browser. All set?

Now we’re ready to create the new application in your Account Dashboard, so let’s navigate to the 'Apps' tab. This is where you can see all your current Twilio Applications and create new ones. Select 'Create App' and complete the form with the following information:

  • Name - the name of your application. Choose whatever you want.
  • Voice URL - points to your web host serving some TwiML. In our case, it should point to the PHP file we created above: http://companyfoo.com/hello-client-monkey-twiml.php.

Click 'Save' to create your app. Now, copy the newly created ApplicationSid and paste it into the token generation code at the top of the client script we created before:

$capability->allowClientOutgoing('APXXXXXXXXXXXXXXXXXXXXXXXXX'); // YOUR APP SID!

Refresh the page. When you press the call button again, you should now be hearing your very own welcome message!