2017-01-20 107 views
1

我有以下的PHP腳本:使用ob_flush()在本地主機上工作,但不能在網上GoDaddy的

<?php 
ob_end_flush(); 
ob_start(); 
for ($i=0; $i < 10; $i++) { 
    echo "Line ".$i."</br>"; 
    ob_flush(); 
    flush(); 
    sleep(1); 
} 
ob_end_flush(); 
?> 

它工作正常,在WAMP本地主機並打印新的生產線每一秒,但在網上GoDaddy的經濟託管,這不是沒有工作。它顯示10秒後沒有任何事情發生,但頁面加載的輸出。

什麼可能是錯的?

+0

調用函數phpinfo();在一個單獨的php腳本中運行它並在主機服務器上運行以查看在GoDaddy主機服務器中是否啓用了ob_flush() –

+0

究竟啓用了什麼功能? – MahmoudTarek

+0

output_buffering = On,或者output_buffering = 4096應該被設置而不是output_buffering = off在你的PHP.ini中 – Kaylined

回答

3
It will work fine.... 

if(!ob_get_level()) ob_start(); 
echo json_encode(array('valid'=>true,'msg'=>'Flush occured.')); 
$size = ob_get_length(); 
header("Content-Type: application/json"); 
// Set the content length of the response. 
header("Content-Length: {$size}"); 
//Close the connection if you want to. 
header("Connection: close"); 
// Flush all output. 
ob_end_flush(); 
ob_flush(); 
flush(); 
// Close current session (if it exists). 
if(session_id()) session_write_close(); 
相關問題