2012-04-27 72 views
0

我想通過讓字符串迭代一定次數來在我的WAMP服務器上實現一個簡單的while循環。但是,儘管在WAMP PHP設置中關閉了輸出緩衝,但整個輸出會立即發生。WAMP和flush()

在以一秒間隔時間版本1

$i = 0; 
while ($i < 5) 
{ 
print ("This is an example of a while loop.<br/>"); 
flush(); 
sleep(1); 
$i++; 

} 

2版

$i = 0; 
while ($i < 5) 
{ 
print ("This is an example of a while loop.<br/>"); 
ob_start(); 
ob_flush(); 
flush(); 
sleep(1); 
$i++; 

} 

既不版本輸出串我打算,即方式,一個。任何幫助是極大的讚賞。

+0

這取決於瀏覽器的時候,以使其... – Ryan 2012-04-27 03:14:45

+0

@dmubu這裏http://www.php.net/manual/en/function.flush.php – Sampson 2012-04-27 03:21:53

+0

閱讀說明還可以閱讀:HTTP: //stackoverflow.com/a/14922225/1454514 – 2015-11-15 21:41:15

回答

0

我一直有WAMP和沖洗的問題,並最終得出結論,它只是在WAMP中被破壞。看起來無論我的服務器設置如何,WAMP的打包方式都有所不同,這是行不通的。

要使它正常工作的唯一方法是使用XAMPP,或者安裝和配置自己的服務器。

+0

我很絕望,直到我關閉了php.ini中的'output_buffering'。一切都很好用flush()現在。 – 2015-11-15 21:40:11

0

我有這個問題,並能夠通過合併下面的代碼來解決它。

// Necessary Settings and stuff for output buffering to work right 
apache_setenv('no-gzip', 1); 
ini_set('zlib.output_compression', 0); 
ini_set('implicit_flush', 1); 
ini_set('output_buffering', "off"); 

// Start a new output buffer and send some blank data to trick browsers 
ob_start(); 
echo str_repeat(" ", 4096); 

for ($i=0; $i < 10; $i++) { 
    echo "<div>Echo Something...</div>\n"; 

    // Call both ob_flush and flush functions 
    ob_flush(); 
    flush(); 
} 
0

對於那些甚至不能使用Justin的解決方法。測試在x64上。

// Necessary Settings and stuff for output buffering to work right 
apache_setenv('no-gzip', 1); 
ini_set('zlib.output_compression', 0); 
ini_set('implicit_flush', 1); 
ini_set('output_buffering', "off"); 

// Start a new output buffer and send some blank data to trick browsers 
ob_start(); 
echo str_repeat(" ", 4096); 
ob_end_flush(); //addition 
ob_flush(); 
flush(); 

for ($i=0; $i < 10; $i++) { 
    ob_start(); //addition 
    echo "<div>Echo Something...</div>\n"; 

    ob_end_flush(); //addition 
    ob_flush(); 
    flush(); 
}