Home >Backend Development >PHP Tutorial >PHP customer service system source code (persistent connection + polling + reverse ajax)

PHP customer service system source code (persistent connection + polling + reverse ajax)

WBOY
WBOYOriginal
2016-08-08 09:32:121487browse

Details: http://www.phpyan.com/home/article/350.htmlTwo implementation methods: One: iframe + server push technology comet (reverse ajax, that is, server-to-browse Server push data) Two: ajax persistent connection + long polling The customer service side adopts the first method: iframe + server push technology Ideas: 1: Create a new comentbyiframe.php file to use while (true) is always connected to the server without disconnecting. If new data is found during the while process, use ob_flush to push it to the apache server. Apache then uses flush to push it to the browser. 2: Create a new html page, Insert an iframe. The src of the iframe is comentbyiframe.php. and hide the iframe. The data obtained by comentbyiframe.php is output to a function in the parent window using js. This function appends the information to the specified chat window3: As long as the client receives the data from the user, it will be displayed as "xx Tell you...". Just click on the username on the customer service side. You can send data to the user. The client uses the second method: ajax persistent connection + long polling ajax persistent connection: After the document is loaded (or other opportunities), use ajax to request a php file The requested php file goes through a while(true) loop, delaying the purpose of returning data to apache. Polling refers to: when requesting the server. If the server has no data, it will wait until the server has data. .Just return it to the client.After requesting and responding like this, an HTTP request is completed. It is not over yet. After the client receives the data, it goes to the server to ask for data. This is polling, just like a beggar. If you don't give him money, he will keep asking for it. After you give him money, he will not be satisfied and come to you again. Implementation idea: After entering the user terminal, if there is no username, use setcookie sets a user name. Then connect persistently through ajax. Keep asking the server for data (that is, the records sent by customer service to the user)

The above introduces the source code of the PHP customer service system (persistent connection + polling + reverse ajax), including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn