Archive for October, 2012

Using twilio without a public web server howto

October 7, 2012 Leave a comment

Why bother:
Most of the twilio tutorials on how to make phone calls require a twiml url and (optionally) status call back url, which might not be desired because either 1) not easy to set up a publicly accessible web server 2) for security reasons it’s better not to to expose some urls to the public even they are just intended for twilio to access. If your application doesn’t require a status call back check, you can follow this post to use twilio for phone calls without setting up a web server.

Basic concept:
1) prepare a twiml url through twimlet echo call
2) create a twilio service object
3) make a call with the service object using the url in step 1, use null as StatusCallBack
4) get the sid for the call made in step 3)
5) wait for a period of time which is enough for step 3) to finish
6) get the status for the call through sid obtain in step 4

Example code (in PHP):
1) go to and put in the following xml code into the textarea:

<Say>Testing 123.</Say>

and save the resulting url for the next step

define('ACCOUNT_SID', 'your_twilio_account_sid');
define('AUTH_TOKEN', 'your_twilio_auth_token');
// from step 1
define('TWIML', '');
require_once 'Path/To/Services/Twilio.php';

$sleep=30;  // seconds to pause before checking the call status
$from='###'; // nbr verified through twilio
$to='###';  // nbr to call
$tw=new Services_Twilio(ACCOUNT_SID, AUTH_TOKEN);

// make a phone call
$call=$tw->account->calls->create($from, $to, TWIML, $opts);

// get its sid

// sleep for some seconds
printf("sleeping for %d seconds now...\n", $sleep);

// now check the call status
printf( "status for [%s] is %s.",  $sid, $call_check->status );

// todo: do something with the $status

As you can see from the above code, the trick is to take advantage of the twimlet echo service (basically we are using that to provide a twiml url which is hosted by

Categories: twilio