(转载)调用ob_end_flush()网页仍旧不能显示有关问题

(转载)http://www.myexception.cn/php/558638.html

调用ob_end_flush()网页仍旧不能显示问题?
写了一个简单的demo,理论上调用ob_end_flush()后,浏览器端应该马上显示网页,但是结果却是整个php文件运行完成才刷新出来,如下代码

PHP code

<?php
@ob_start();

include 'test.tpl.php';

@ob_end_flush();

sleep(3);

//---------------------------------------------------------------------
// invoke client js
$s = sprintf("\n<script>%s.%s();</script>", 'oCar', 'updateDiv1');

// output the buffer to client
echo $s;
unset($s);
@flush();

//----------------------------------------------------------------------
sleep(3);
// invoke client js
$s = sprintf("\n<script>%s.%s();</script>", 'oCar', 'updateDiv2');

// output the buffer to client
echo $s;
unset($s);
@flush();



------解决方案--------------------------------------------------------
试试改下php.ini对于输出的设置
output_buffering = Off // 如果设置为On ,那么默认会先缓存4096B的输出内容
implicit_flush = On // I don't know...
 http://dao.daimaku.com/post/view/id/158
------解决方案--------------------------------------------------------
浏览器缓存

 

 

 


例子1:

<?PHP
$number = 0;

for ($i = 0; $i < 10; $i++) 
{  
    echo $number++;
//     echo "ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd".'<br>';
    ob_flush();
    flush();  
    sleep(1);
}  
?>

implicit_flush = Off修改为implicit_flush = On了。

然后上面的例子有时候可以输出有时候又不能。

posted @ 2013-06-22 10:30  robotke1  阅读(382)  评论(0编辑  收藏  举报