我想你混淆了
ob_flush()用
flush()。虽然
ob_start()并
ob_flush()处理捕获所有输出的PHP内部输出缓冲区,但它
flush()是正常的函数,
STDOUT像其他编程语言一样进行刷新。
例:
<?phpob_start();echo "FoobarnFoobarnFoobarn";// Nothing printed yetob_flush(); // Now it is printed.echo "Foobarn"; // Printed directly, because contains a line ending.echo "Foobar"; // Not printed, because normally buffers are flushed on line endingsflush(); // Printed.
编辑:
您的输出未打印,因为您的Web服务器可能会缓冲内容。尝试关闭压缩和输出缓冲:
@apache_setenv('no-gzip', 1);@ini_set('zlib.output_compression', 0);@ini_set('implicit_flush', 1);还请记住,Safari和Internet Explorer具有内部1K缓冲区。因此,您需要添加1 KB的填充数据(如空格)以使其呈现。
编辑2: 您的实现已损坏。您想使用ajax轮询数据。在客户端使用jQuery:
<div id="counter">0%</div><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"><script type="text/javascript">function doPoll(){ $.post('script-that-returns-stuff.php', function(data) { $("#counter").html(data); setTimeout(doPoll,5000); });}doPoll();</script>然后在
script-that-returns-stuff.php:
<?php$file = explode("n", file_get_contents("/tmp/output.txt"));$last_line = $file[count($file)-1];echo $last_line."%";

![PHP错误:ob_flush()[ref.outcontrol]:无法刷新缓冲区。没有要刷新的缓冲区 PHP错误:ob_flush()[ref.outcontrol]:无法刷新缓冲区。没有要刷新的缓冲区](http://www.mshxw.com/aiimages/31/413628.png)
