php 定时输出

来源:互联网 发布:淘宝欧斯曼真皮双肩包 编辑:程序博客网 时间:2024/06/14 09:58
I hope this code will help somebody to solve the problem of not being able to flush or output the buffer to the browser (I use IE7).
It may work for you with just [ echo str_repeat(".", 4096); ] and without even using ob_... and flush.

<?php
ob_start
();

ob_implicit_flush(true);
//[ OR ] echo "..."; ob_flush(); flush();

set_time_limit(0);

function
sleep_echo($secs) {
   
$secs = (int) $secs;
   
$buffer = str_repeat(".",4096);
   
//echo $buffer."\r\n<br />\r\n";
   
for ($i=0;$i<$secs;$i++) {
        echo
date("H:i:s",time())." (".($i+1).")"."\r\n<br />\r\n".$buffer."\r\n<br />\r\n";
       
ob_flush();
       
flush();
       
sleep(1);
       
//usleep(1000000);
   
}
}

sleep_echo(30);

ob_end_flush();
?>
原创粉丝点击