私は現在リアルタイムSMSシステムに取り組んでいますが、私の現在の実装はひどい習慣であり、私はこれをより効率的にするためのガイダンスを探しています。PHPとTwilioリアルタイム?
あなたはそれはあなたが選択したその番号のすべてのテキストメッセージを引っ張るインタフェースをロードしようとしました現在
、。それから、リストの最後のメッセージよりも新しいメッセージを求めて書いたTwilio JSON PHPスクリプトに、5秒ごとにajaxコールを発生させます。ここ
$.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);
});
アップデート機能
function 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");
}
});
}
}
コードレビューのリクエストは、ここではオフトピックです。そのような質問には適切な[SEサイト](http://codereview.stackexchange.com/)があります。 – hindmost