Mike Hillyer's Personal Webspace Gentlemen! Look, and Behold!

14Feb/10Off

Twilio: Rolling My Wife’s Eyes in 31 Lines of PHP

And then she gives you that look

The Look - Flickr user Nabo, used under CC license

For some reason a certain number of my little side projects result in "The Look", that rolled-eyes expression that let's me know I'm such a nerd. Given that Valentine's Day fell on a weekend this year and I had a little free time this Sunday morning, the look was inevitable.

Today I finally had a few minutes to try out Twilio, a new web services provider that helps to telephone-enable applications through an easy REST API. In the case of PHP it is made even easier through a helper library provided by Twilio on their developer site.

Twilio is free to sign up and they provide a generous starting credit to begin exploring their service in a sandbox environment (they let you use their sandbox number for incoming call tests and put a watermark message on the front of all your outgoing communications). You can send and receive calls, add interactive menus to the calls, use recorded voice clips or text-to-speech and even send and receive text messages, all through their APIs and XML formatted speech scripts.

My Hello World test for the morning was simple; I wanted to call my home number and deliver a Valentine's Day greeting. To do so I first signed up with Twilio, then went to my Twilio dashboard for my API key and to download the twilio.php helper library.

I then created helloworld.php with the following:

<?php
require "twilio.php";
 
/* Twilio REST API version */
$ApiVersion = "2008-08-01";
 
/* Set our AccountSid and AuthToken */
$AccountSid = "ACxxxxxxxxxxxxxx";
$AuthToken = "xxxxxxxxxxxx";
 
/* Outgoing Caller ID you have previously validated with Twilio */
$CallerID = '2223334444';
 
/* Instantiate a new Twilio Rest Client */
$client = new TwilioRestClient($AccountSid, $AuthToken);
 
/* make Twilio REST request to initiate outgoing call */
$response = $client->request("/$ApiVersion/Accounts/$AccountSid/Calls",
    "POST", array(
        "Caller" => $CallerID,
        "Called" => '4445556666',
        "Url" => "http://mysite.com/helloworld.xml"
    ));
    if($response->IsError)
        echo "Error: {$response->ErrorMessage}";
    else
        echo "Started call: {$response->ResponseXml->Call->Sid}";
?>

Initiating a call just requires a number to "call from" (in reality it's just the number the Twilio system presents as caller ID), a number to call to, and the Account ID and token. The URL specified in the request to call out is an XML document that defines what happens during the call, using a format referred to as TwiML:

<Response>
        <Say>Happy Valentine's Day!</Say>
</Response>

In this case things are pretty straightforward, the system also has the ability to play mp3 files, take responses and branch based on keypresses and perform a number of additional actions. It looks like one could easily build a menu system or a survey system.

All in all an interesting offering that I'll be tinkering with more in the future.

29Jan/10Off

Review – Joe Celko’s Trees and Hierarchies in SQL for Smarties

When I started looking into managing hierarchical data I found a lot of short articles that provided bits and pieces of the big picture, but nothing gave a good in-depth review of everything I needed to know to handle hierarchies.

One trend that began to develop was that the best information on the subject was coming from Joe Celko, a rather prolific author/speaker on all things SQL.

Joe Celko has a book in publication called SQL For Smarties, and this book had some basic information on handling hierarchies, which he followed up with Trees and Hierarchies in SQL for Smarties, a truly excellent book on the subject.

This book is not for the faint of heart, but it really is a must-read for those who are looking to handle hierarchies in SQL.

The book only addresses MySQL once, and while in that section it repeats Joe's opinion of MySQL not being a real database, users of MySQL 5 can rest assured that the stored procedure examples in the book work without modification (thanks to Joe and MySQL 5 both using the standard PL/PSM stored procedure syntax).

Overall this is an excellent book for those looking to implement hierarchical data in SQL.

Filed under: Books, MySQL, Reviews 3 Comments
12Jan/10Off

Cinematic Titanic – East Meets Watts

East Meets Watts is the latest installment from Cinematic Titanic and the first live DVD made available since Cinematic Titanic started performing live, and it's a blast! The DVD starts out with a camera covering the entire stage and then cuts to a composite image that places the performers at the sides of the movie so that the movie image is nice and sharp. This approach takes full advantage of the DVD aspect ratio and unlike a shadowrama performance ensures that the movie is never obscured (for better or worse).

With East Meets Watts (AKA Dynamite Brothers) we have a performance that's been honed over a number of live performances and the performers seem to be really settled into their groove. The riffs are as fast and furious, more so than the on-screen action and while the episode lacks some of the skit segments of its predecessors it's nice to actually see the performers for one (a synchronized spit-take partway through is better with a live camera).

Instead of a shorter trailer, Cinematic Titanic instead published a five minute segment to YouTube, so you can see for yourself how the live version works:

I'd suggest picking it up, either on DVD or instant download.