I'm currently working on a real-time SMS System but I'm fairly positive that my current implementation is a terrible practice and I'm looking for guidance to be more efficient with this.The AttemptCurrently, when you load up the interface it pulls all the text messages for that number you have selected. Then it fires off an ajax call every 5 seconds to the Twilio JSON PHP script I've written asking for messages newer than the last message in the list.Global Variables:var lastMessage;var sms_interval;Fetch All Current SMS Messages.$.getJSON(/includes/twilio.php,{action:getconvo,cid:customer.customer_number},function(data){        $('#sms_messages').html(<div></div>);        $(data.messages).each(function(){            insertSMS(this.msg,this.date,this.from);            lastMessage = this.date;        });        $(#sms_messages).animate({ scrollTop: $('#sms_messages > div').height()},fast);        shouldUpdate = true;        sms_interval = setInterval(function(){updateSMS(customer.customer_number)},5000);});Update Functionfunction updateSMS(cid){    if(shouldUpdate){        $.getJSON(/includes/twilio.php,{action:getconvo,cid:cid,date:lastMessage},function(data){            if(data.messages.length > 0){                // Play an embeded sound effect when a new message is found.                $('#sms_sound')[0].play();                $(data.messages).each(function(){                    insertSMS(this.msg,this.date,this.from);                    lastMessage = this.date;                });                $(#sms_messages).animate({ scrollTop: $('#sms_messages > div').height()},fast);            }        });    }}
Twilio Real-time SMS with JQuery and PHP
javascript;php;jquery