简体   繁体   English

了解PHP中的flush,Ob_flush和buffer_output

[英]understanding flush,Ob_flush and buffer_output in PHP

i was reading about the buffering of contents and i found a simple script to show effects of flush 我正在阅读有关内容缓冲的信息,我发现了一个简单的脚本来显示冲洗效果

<?php

if (ob_get_level() == 0) ob_start();

for ($i = 0; $i < 10; $i++) {

    echo "<br> Line to show.";
    echo str_pad('', 4096) . "\n";

    ob_flush();
    flush();
    sleep(2);
}

echo "Done.";

ob_end_flush();

?>

this script works fine and show the output , but when i remove the str_pad or reduce the length from 4096 to 40 flush does not work. 这个脚本可以正常工作并显示输出,但是当我删除str_pad或将长度从4096减少到40时,flush不起作用。

can any one help me out what exactly causing this.. 谁能帮我弄清楚是什么原因造成的。

Atlast i found the reason. 最后,我找到了原因。

According to PHP.net Broswers require certain bytes to start the display of the page. 根据PHP.net, Broswers需要某些字节才能开始页面显示。 Like some version of Internet Explorer require 200 bytes. 像某些版本的Internet Explorer需要200字节。 And modern broswers like Firefox or Chrome requires more bytes to start Browser display. 像Firefox或Chrome这样的现代浏览器需要更多字节才能启动浏览器显示。

In above case if you check it in Internet Explorer it will not require string padding but in Firefox or Chrome you need to Padd spaces with input to display flushed output. 在上述情况下,如果您在Internet Explorer中选中它,则不需要字符串填充,但是在Firefox或Chrome中,您需要使用输入来填充空格以显示刷新的输出。

我认识到这个问题,我自己遇到过一次。.您是否激活了输出压缩?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM