停止 PHP 输出缓冲

发布于 2024-09-06 16:31:44 字数 211 浏览 7 评论 0原文

我需要显示 php 脚本的连续输出。该脚本将停留在从设备打印日志数据并休眠的循环中。我的问题是在脚本完成之前我无法让 PHP 或 Apache 输出数据。

我已经尝试了所有刷新输出缓冲区的命令,并且我已经阅读了 PHP 和 Apache 的配置文件,寻找要禁用的某种类型的缓冲。

这是否可以在 Windows 上使用 Apache 和 PHP 来实现,还是我应该考虑其他平台?

I need to display continuous output from my php script. The script will stay in a loop of printing log data from a device and sleeping. My problem is that I can't get PHP or Apache to output data before the script is completed.

I have tried all the commands for flushing the output buffer, and I have read through the config-files for both PHP and Apache looking for some type of buffering to disable.

Is this possible to do with Apache and PHP on Windows, or should I consider some other platform?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缱绻入梦 2024-09-13 16:31:45

完成此操作的最佳方法(最可靠和最干净)是使用执行该工作的服务器端脚本和客户端 AJAX 脚本,该脚本将轮询另一个将返回状态的服务器端脚本。在Web中,数据是分层次缓冲的,以达到优化的目的,因此很难达到你想要的效果。

The best way (most reliable and clean) to accomplish this is to use a server-side script which does the work, and a client-side AJAX script which will poll another server-side script which will return the status. In the web, data is buffered at different levels, to achieve optimization, and therefore it is difficult to accomplish what you want.

大姐,你呐 2024-09-13 16:31:45

使用您已经使用过的这些刷新输出缓冲区命令,并放入 1024 字节长的 HTML 注释。因为这很可能是浏览器问题,而不是服务器问题。

啊,看来您正在寻找 COMET 应用程序

http://www.zeitoun.net/articles/comet_and_php/start

Use these flushing the output buffer commands you've used already, and throw in an HTML comment, 1024 bytes long. Cause it's most likely browser issue, not server.

Ahh, looks like you're looking for the COMET application

http://www.zeitoun.net/articles/comet_and_php/start

苯莒 2024-09-13 16:31:45

PHP 的 output_buffering 设置默认为 0(即关闭),但您无疑已经对此进行了调查。

我认为 @Palantir 的建议可能是一个不错的建议:将日志条目写入本地文件,然后将该文件(或其部分)提供给客户端;客户可以根据您的意愿重新请求。这还有一个优点,即不会填满浏览器的缓冲区(即您不应该无限期地向客户端发送日志数据)。

但这不是你的问题。

您可以使用如下所示的简单脚本重现输出缓冲问题吗?

<?php
while (TRUE)
{
    echo 'x';
    flush();
    sleep(1);
}
?>

PHP's output_buffering setting is 0 by default (i.e. off), but you've no doubt investigated that.

I think @Palantir's suggestion is probably a good one: write the log entries to a local file, and then serve up that file (or parts thereof) to the client; the client can re-request however often you desire. This also has the advantage of not filling up the browser's buffer (i.e. you shouldn't just keep sending log data to the client ad infinitum).

But that wasn't your question.

Can you reproduce the output buffering problem with a simple script like the following?

<?php
while (TRUE)
{
    echo 'x';
    flush();
    sleep(1);
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文