Joseph Tinsley Solves A Class Registration Nightmare For His Niece With Twilio SMS

July 21, 2015
Written by

registration

Registering for college classes is a lot like shopping on Black Friday here in America. You’ve probably seen the videos of people stampeding through the doors of a superstore at 4am to get their hands on an Xbox. That’s what class registration is like in a virtual sense.

When thousands of students all hit the registration page at once, it can crash. The downtime couldn’t come at a worse time. One class can mean the difference between graduating on time and not graduating on time. When Joseph Tinsley’s niece texted him at midnight, saying her school’s registration page was down, he sprang into action. Using Twilio SMS, he built his niece an alert system so she could register for classes the second the site went back up.

“The problem is everyone is gunning to take Anatomy with this teacher. Registering for classes at this school is a first come first service type of process, hence the reason why we had so much panic,”Joseph says.

Joseph is an SEO specialist who has used Twilio a number of times before. When his niece was in need, he set up a cron job to ping the school’s website  every 5 minutes and text him when it was back up. “A lot can happen within five minutes,” he says.

The site had been down for hours and hours. While Joseph was getting gas, he got a text from Twilio, notifying him that the site was live. He immediately texted his niece who jumped to the computer and nabbed the class that so many students were vying for.

“If it wasn’t for Twilio and the ability it offers to quickly include SMS technology, we may have not been able to take advantage of that small window of opportunity.”

You can check out the conversation between Joseph and his niece below, and the code he used to build the Twilio app.

JosephSetUp
<?PHP
require_once './inc/twilio/api.twilio.php';

class SiteLive {
    
    
    const VOICETYPE = 'woman';
    protected  $twilioClient;
    protected  $ApiVersion = "2010-04-01";
    protected  $AccountSid = "ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”;
    protected  $AuthToken =  "3faxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
         
    public function curlIt($url) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, trim($url));
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_NOBODY, true); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 35);
        curl_exec($ch);
        $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        
        if($httpcode > 0){
            $this->sendSMS('334-xxx-xxxx','334xxxxxxx', 'Check the http://suscc.edu/ registration site');
        }
    }
    

    private function sendSMS($smsFromNumber,$smsNumber, $msgStr){
        
        if( !empty($smsNumber) && !empty($msgStr) ){
            
            $smsNumber = $this->format_phone($smsNumber);

            /* Send a new outgoinging SMS by POST'ing to the SMS resource */
            $this->twilioClient = new TwilioRestClient($this->AccountSid, $this->AuthToken);
            $this->twilioClient->request("/$this->ApiVersion/Accounts/$this->AccountSid/SMS/Messages",
            "POST", array(
            "To" => $smsNumber,
            "From" => $smsFromNumber,
            "Body" => "$msgStr"
            ));

        }
    }

    private function format_phone($phone){
        $phone = preg_replace("/[^0-9]/", "", $phone);

        if(strlen($phone) == 7)
            return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
        elseif(strlen($phone) == 10)
            return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1-$2-$3", $phone);
        else
        return $phone;
    } 
     
}//END CLASS

$url = 'http://domain.com/page.php';

$Run = new SiteLive();
$Run->curlIt($url);