如何实时回显输出(脚本结束之前)? [英] How to echo output in real time, (before script finishes)?

查看:160
本文介绍了如何实时回显输出(脚本结束之前)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在脚本执行前输出到浏览器?



例如,下面的代码会一次输出100个hi使它能够在代码段被读取/处理后立即输出例如:PHPBB3论坛显示安装过程一步一步。

 <?php 
for($ i = 0 ; $ i <= 100; $ i ++){
echohi;
echo< br>;
}
?>


解决方案

在循环之前调用ob_implicit_flush >

请注意,这不是一个保证(web服务器缓冲区,代理缓冲区和web浏览器谁拒绝提交是你的敌人)。它可能会帮助回复一些换行符(\\\
),因为我似乎记得有些浏览器在收到完整的行之前不会退出。



这不会如果你使用输出缓冲(例如,使用gzip进行压缩(如果你使用的gzip模块使用缓冲,这并不罕见)或其他原因)或

How do i output to the browser before the script finishes executing?

For example, the code below will output all 100 "hi" at once, how do I make it so it will output as soon as that section of code is read/processed? For example: PHPBB3 forum shows installing process step by step.

<?php
for ($i = 0; $i <= 100; $i++) {
   echo "hi";
   echo "<br>";
}
?>

解决方案

Call ob_implicit_flush() before your loop.

Note that this is not a guarantee (web server buffers, proxy buffers and web browsers who refuse to rerender are your enemy). It MAY help to echo some linefeeds (\n) as I seem to remember that there are browsers who will not rerender until they received a complete line.

This will not work at all if you use output buffering (e.g. for compression using gzip (if the gzip modul you use uses buffering which is not uncommon) or other reasons).

这篇关于如何实时回显输出(脚本结束之前)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆