如何在所有浏览器上的每次回显时正确显示输出?
我将文件移至新服务器,并且有一个脚本可以立即在浏览器的每次回显上显示输出,但这在新服务器上不起作用。这是我的测试代码:
@ini_set('output_buffering', 0); @ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) ob_end_flush();
ob_implicit_flush(1);
ignore_user_abort(true); set_time_limit(0);
$max_wait_time = 30;
$begin_time = microtime(true);
$elapsed_time = 0;
while(!connection_aborted()) {
echo $i++.str_repeat(' ', 1020).'<br/>';
flush(); ob_flush();
usleep(1000000);
if($elapsed_time > $max_wait_time){ break; }
$elapsed_time++;
}
我尝试了一些已经成为上面的内容。但是打开输出缓冲和刷新对我来说不起作用。我已经在 Chrome 和 Firefox 上对此进行了测试,它们都只是在最后输出所有内容。
有什么想法吗?
I moved my files to a new server and I had a script that instantly showed output on every echo
to the browser, but this isn't working on the new server. Here is my test code:
@ini_set('output_buffering', 0); @ini_set('implicit_flush', 1);
for ($i = 0; $i < ob_get_level(); $i++) ob_end_flush();
ob_implicit_flush(1);
ignore_user_abort(true); set_time_limit(0);
$max_wait_time = 30;
$begin_time = microtime(true);
$elapsed_time = 0;
while(!connection_aborted()) {
echo $i++.str_repeat(' ', 1020).'<br/>';
flush(); ob_flush();
usleep(1000000);
if($elapsed_time > $max_wait_time){ break; }
$elapsed_time++;
}
I've tried a few things which has become the above. But turning output buffering on and flushing hasn't worked for me. I have tested this on Chrome and Firefox, they both just output everything at the end.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
摘自
flush
文档:您很有可能更改为不同的 Web 服务器(或 Web 服务器配置),它会在输出之前缓冲整个脚本的输出。
Excerpt from the
flush
documentation:Chances are high that you changed to a different web server (or web server configuration), which buffers the output of the whole script before outputting it.
您正在寻找的设置位于您的 PHP.ini 中,它被称为 output_buffering:
手动将其设置为关闭并重新启动您的网络服务器,以使 flash() 在您需要时实际刷新某些内容,而不是在 4kb 数据之后刷新:)
请注意 ini_set并不总是必须为此工作。如果您想要完全控制,请在 php.ini 本身中禁用它,或作为 .htacces php_value 标志禁用它
The setting you're looking for is in your PHP.ini and it's called output_buffering:
Set it to off manually and restart your webserver to make flush() actually flush something when you want it, not after 4kb of data :)
Note that ini_set doesn't always necessarily has to work for this. If you want full control, disable it in php.ini itself, or as a .htacces php_value flag
浏览器自行决定何时输出内容。因此,如果您没有达到该阈值,他们只会等到满足该阈值,然后才向用户显示更多内容。
Browsers decide for themselves when to output content. So if you don't meet that threshold, they'll just wait until it is met and only then show more content to the user.
尝试添加到.htaccess
Try to add to .htaccess