Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a true long polling?
    primarykey
    data
    text
    <p>After lot of trials,I am successfully able to maintain continous server connection with database. Now code keet cheking and show the messages,if there are new in database.</p> <p>Plz review and tell <strong>if there is true long polling technique used in this code?</strong> If it is not,then plz suggest,where I am wrong(deviating from long polling) and how this can be made a true long polling.</p> <p>Currenlty,I am getting these errors.However still it maintains the continous connection with database.</p> <ol> <li><strong>each time,Only one message is pulled instead of all.</strong>(I used .each loop but it stops the long polling)</li> <li><p>After every 10/15 seconds,token error apperes(<strong>Parse erroe(syntax error=unexpected token)</strong>).</p> <pre><code>var last_msg_id = 2; function load_msgs() { $.ajax({ type:"Post", url:"getdata.php", data:{ last_msg_id:last_msg_id }, dataType:"json", async:true, cache:false, success:function(data) { var json = data; $("#commidwin").append(json['msg']); last_msg_id = json["last_msg_id_db"]; setTimeout("load_msgs()", 1000); }, error:function(XMLhttprequest, textstatus, errorthrown) { alert("error:" + textstatus + "(" + errorthrown + ")"); setTimeout("load_msgs()", 15000); } }); } </code></pre></li> </ol> <p>Php file is here</p> <pre><code> $last_msg_id=$_POST['last_msg_id']; $last_msg_id_db=1; while($last_msg_id&gt;$last_msg_id_db){ usleep(10000); clearstatcache(); $sql=mysqli_query($db3-&gt;connection,"SELECT * FROM chat_com where id&gt;'$last_msg_id' ORDER by id ASC"); $sql_m=mysqli_query($db3-&gt;connection,"SELECT max(id) as maxid FROM chat_com"); $row_m=mysqli_fetch_array($sql_m); $last_msg_id_db=$row_m['maxid']; while($row=mysqli_fetch_array($sql)){ $textt=$row['mesg']; $last_msg_id_db=$last_msg_id_db; $response=array(); $response['msg']=$textt; $response['last_msg_id_db']=$last_msg_id_db; } } echo json_encode($response); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload