Web QQ has been used, which involves the technology, there is a reverse Ajax.
Reverse Ajax is also called Comet,server push, server push technology.
Application: web chat server, Sina Weibo online chat, Google Mail web chat, all useful.
Principle: Generally speaking, the characteristics of HTTP protocol, connection <-> disconnection.
When is the specific time to disconnect?
The server responds Content-length, and when it receives the content of the specified length, it is disconnected.
In the http1.1 protocol, you are allowed to not write content-length, such as when the length of the content to be sent is really unknown.
At this point, a special content-type:chunked is required
<?phpset_time_limit (0); Ob_start (); $pad = Str_repeat (", 4000); Echo $pad, ' <br/> '; Ob_flush (); flush (); Send the resulting content to the browser immediately instead of waiting for the script to end. $conn = mysql_connect (' localhost ', ' root ', ' 111111 '), mysql_query (' Use test ') and while (1) { $sql = ' select * from msg where flag = 0 '; $rs = mysql_query ($sql, $conn); $row = Mysql_fetch_assoc ($rs); if (!empty ($row)) { echo $pad, ' <br/> '; echo $row [' content '], ' <br/> '; mysql_query (' Update msg set flag=1 '); } Ob_flush (); Flush (); Send the resulting content to the browser immediately instead of waiting for the script to end. Sleep (1);} /* Read the contents of the database so that it can be achieved, instant communication. Server-Side---uninterrupted--push message--to client */
HTTP protocol with chunked transfer, persistent connection and reverse Ajax