每次`echo`调用后如何刷新输出? [英] How to flush output after each `echo` call?

查看:51
本文介绍了每次`echo`调用后如何刷新输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 php 脚本,它只向客户端生成日志.
当我回显某些内容时,我希望将其即时传输到客户端.
(因为脚本在处理时,页面是空白的)
我已经玩过 ob_start()ob_flush(),但它们没有用.

I have a php script that only produces logs to the client.
When I echo something, I want it to be transferred to client on-the-fly.
(Because while the script is processing, the page is blank)
I had already played around with ob_start() and ob_flush(), but they didn't work.

最好的解决方案是什么?

What's the best solution?

PS:在echo 调用的末尾放一个flush 有点脏...

PS: it is a little dirty to put a flush at the end of the echo call...

答案都不起作用,PHP 还是 Apache 故障?

Neither the Answers worked, PHP or Apache Fault?

推荐答案

我在阅读手册页上的评论时遇到了一个错误 指出 ob_implicit_flush 不起作用,以下是它的解决方法:

I was reading the comments on the manual page and came across a bug that states that ob_implicit_flush does not work and the following is a workaround for it:

ob_end_flush();

# CODE THAT NEEDS IMMEDIATE FLUSHING

ob_start();

如果这不起作用,那么甚至可能发生的情况是客户端不会从服务器接收数据包,直到服务器建立足够的字符来发送它认为值得发送的数据包.

If this does not work then what may even be happening is that the client does not receive the packet from the server until the server has built up enough characters to send what it considers a packet worth sending.

旧答案:

您可以使用 ob_implicit_flush 这将告诉输出缓冲关闭缓冲一段时间:

You could use ob_implicit_flush which will tell output buffering to turn off buffering for a while:

ob_implicit_flush(true);

# CODE THAT NEEDS IMMEDIATE FLUSHING

ob_implicit_flush(false);

这篇关于每次`echo`调用后如何刷新输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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