Quoting the example of "Starry Sky Prodigal" PHP Chinese document:
Chat room is the secret weapon for boring people on the website. At the same time, the webmaster or other personnel can also kill time here. Even if a vigorous online romance occurs, even if it doesn't happen, it can at least increase the typing speed.
A chat room is actually a CGI program used by multiple people. The program sorts the strings entered by each person according to the time when the system receives them, and then sends them to each user. The difference between Web chat rooms and BBS chat rooms is that BBS chat rooms can immediately distribute every sentence received to every Internet user in the chat room; Web CGI programs cannot always connect like BBS telnet. line, Web CGI must send information out as quickly as possible and then end the connection. This situation occurs because Web chat rooms still use the HTTP transmission protocol. The version of HTTP implementation, whether it is version 0.9, 1.0 or 1.1, cannot occupy the network connection port for a long time.
In order to solve the problem of data not being transferred immediately and the problem of updating information, Netscape used new technologies after the 3.0 version of the browser, and Internet Explorer also implemented these technologies developed by Netscape. Netscape divides it into two technologies: Server Push and Client Pull. Server Push uses multiple MIME encodings from the Web server to send data to the user. Currently, few websites use this method; while Client Pull uses the HTML meta tag and the http-equiv="Refresh" attribute. , indicating that the data needs to be reloaded. As for the loading time, the content attribute is used to achieve it.
tags are usually placed in the section of
.. so that the browser can prepare to update the user-side web page. The following is an example of meta and PHP, set to reload every fifteen seconds.
If you don’t use Server Push or Client Pull To create a chat room, is there any other way to enable chatting in a Web browser? The answer is yes. You can use Java or ActiveX (limited to IE4 and 5) or even develop your own dedicated Browser Plug-in program (such as Qimo's chat room), but this has nothing to do with PHP and is not our focus.
In addition, since all netizens’ messages are updated regularly, in order to avoid half-written strings being cleared due to refresh, the chat room is built using frame technology. It is necessary. The following example is the main program of the chat room.
Chat Room