2017-01-20 15 views
1

でオンラインでローカルホストに取り組んではなく:ob_flush()私は、次のPHPスクリプトを持っている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(); 
?> 

それはホスティングGoDaddyの経済オンラインでlocalhostのWAMPで正常に動作し、新しい行に各秒を印刷し、しかし、それはdoesnの仕事はありません。 10秒後に何も起こらずにページが読み込まれた後の出力を示します。

何が間違っている可能性がありますか?

+0

関数phpinfo()を呼び出します。別のPHPスクリプトで実行し、ホストサーバー上で実行して、GoDaddyのホストサーバーでob_flush()が有効になっているかどうか確認してください。 –

+0

正確には何が有効になっていますか? – MahmoudTarek

+0

output_buffering =オン、またはoutput_buffering = 4096をPHP.iniのoutput_buffering = offの代わりに設定する必要があります – 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(); 
関連する問題