Home > Backend Development > PHP Tutorial > 缓冲区问题求救

缓冲区问题求救

WBOY
Release: 2016-06-06 20:11:43
Original
1040 people have browsed it

php中ob是关闭的,我想问下在关闭的情况下,一个echo是经过php缓冲区到系统服务器缓冲区到浏览器缓冲区的。如果是开启了过程是怎样的?还是我理解错了?

回复内容:

php中ob是关闭的,我想问下在关闭的情况下,一个echo是经过php缓冲区到系统服务器缓冲区到浏览器缓冲区的。如果是开启了过程是怎样的?还是我理解错了?

ob指的是输出控制,并不是指缓冲,打开ob后,你就可以控制php中输出的内容何时发送给浏览器了。
给你举个例子:

不开obecho '1' -> send '1' to browser -> echo '2' -> send '2' to browser

obecho '1' -> do nothing -> echo '2' -> do nothing -> flush -> send '12' to browser

开启ob,下列程序会有一条条输出特效

<code><?php if(ob_get_level()==0)      //判断缓冲区等级,如果没有活动缓冲区
ob_start();
for($i=0;$i<10;$i++)      //循环执行操作
{
    echo "$i:line to show.<br>";    //输出内容
    echo str_pad('',1025);    //输出生成的字符串,如果字符串过短不会有效果。

    ob_flush();       //发送缓冲区数据
    flush();        //刷新缓冲区
    sleep(1);       //暂停1秒
}
echo "done.";       //输出操作完成标记
ob_end_flush();       //发送缓冲区数据,并关闭缓冲区
?>
</code>
Copy after login
Related labels:
php
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