nginx环境下php在浏览器缓存实时输出结果
nginx 里面 flush 默认是无效的, 这个函数默认是作用在php作为 apache模块时才有效,如果需要 nginx 里面支持,需要加上一行
header('X-Accel-Buffering: no');
我的代码是
header('X-Accel-Buffering: no'); header('Content-type:text/html;charset=utf-8'); #设置执行时间不限时 set_time_limit(0); ob_start(); $i = 1; while (true) { echo str_pad(' ', 4096); echo $i++, '<br />'; ob_flush(); flush(); sleep(1); }