: This article mainly introduces round robin, long polling, long connections, and FlashSocket. if you are interested in the PHP Tutorial, refer to it.
- Round Robin: The client periodically sends an Ajax request to the server. after receiving the request, the server immediately returns the response and closes the connection.
Advantage: it is easier to write back-end programs.
Disadvantage: most requests are useless, wasting bandwidth and server resources.
Instance: suitable for small applications.
- Long polling: the client sends an Ajax request to the server. after receiving the request, the server holds the connection and returns the response information and closes the connection until a new message exists, after processing the response information, the client sends a new request to the server.
Advantage: no messages are sent frequently.
Disadvantage: server hold connections consume resources.
Examples: WebQQ, Hi web edition, and Facebook IM.
In addition, there are also differences between persistent connections and socket connections:
- Persistent connection: embed a hidden parameter iframe in the page and set the src attribute of the hidden parameter iframe to a persistent connection request. the server can continuously input data to the client.
Advantage: messages arrive immediately without sending useless requests.
Disadvantage: maintaining a persistent connection increases overhead.
Example: Gmail chat
- Flash Socket: embed a Socket-type Flash program JavaScript in the page to call the Socket interface provided by the Flash program to communicate with the Socket interface on the server, after receiving the information sent by the server, JavaScript controls the display of the page.
Advantage: implement real-time communication instead of pseudo-real-time communication.
Disadvantage: The Flash plug-in must be installed on the client; non-HTTP protocol, the firewall cannot be automatically crossed.
Example: online interactive games.
The preceding describes the four request methods and compares their advantages and disadvantages.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above describes the polling, long polling, long connection, Flash Socket, including the content, hope to be helpful to friends who are interested in PHP tutorials.