Reverse ajax, comet, server push

WBOY
Release: 2016-08-08 09:25:51
Original
1314 people have browsed it

<code><span><span><?php</span>
set_time_limit(<span>0</span>);
ob_start();
<span>$str</span>=str_repeat(<span>' '</span>,<span>4000</span>);
<span>echo</span><span>$str</span>;
ob_flush(); <span>//把产生的内容,立即送给浏览器而不要等脚本结束后再一起送</span>
flush();
<span>$i</span>=<span>1</span>;
<span>while</span>(<span>$i</span>++) {
    <span>echo</span><span>$str</span>,<span>'<br/>'</span>;
    <span>echo</span><span>$i</span>,<span>'<br/>'</span>;
    ob_flush();
    flush();    <span>//把产生的内容,立即送给浏览器而不要等脚本结束后再一起送</span>
    sleep(<span>1</span>);
}

<span>/*
思考:如果while循环中,不是1,2,3...
而是数据库中的内容呢?
而是2人的聊天记录呢?
这样就能达到,即时通信

服务器端----不间断---推送信息---->客户端
*/</span></span></code>
Copy after login

The above has introduced reverse ajax, comet, and server push, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!