PHP中刷新输出缓冲,立即输出数据

<script type="text/javascript">
function show_message(message) {
	document.getElementById('notice').innerHTML += message + '<br />';
	document.getElementById('notice').scrollTop = 100000000;
}


</script>

<div id="notice" style="width:950px; height: 200px; overflow:scroll; word-break: break-all; word-wrap:break-word;"></div>

<?php
//echo str_pad(" ", 256);  
echo str_pad(" ", 1000);  // 保证缓冲区数量
function showjsmessage($message) {
	echo '<script type="text/javascript">show_message(\''.addslashes($message).' \');</script>'."\r\n";
	flush();
	ob_flush();
}

for ($i=0; $i < 100; $i++) {
	showjsmessage($i);
	sleep(1);
}
?>

  

posted @ 2015-07-29 17:49  Adtuu  阅读(226)  评论(0编辑  收藏  举报