如何从 Apache 2 提供无缓冲的 CGI 内容? [英] How can I serve unbuffered CGI content from Apache 2?

查看:20
本文介绍了如何从 Apache 2 提供无缓冲的 CGI 内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够允许用户查看长时间运行的 GCI 脚本的输出,因为它是在生成时而不是在脚本完成后.但是,即使我明确刷新 STDOUT,服务器似乎也在向客户端发送响应之前等待脚本完成.这是在运行 Apache 2.2.9 的 Linux 服务器上.

I would like to be able to allow a user to view the output of a long-running GCI script as it is generated rather than after the script is complete. However even when I explicitly flush STDOUT the server seems to wait for the script to complete before sending the response to the client. This is on a Linux server running Apache 2.2.9.

Python CGI 示例:

Example python CGI:

#!/usr/bin/python

import time
import sys


print "Content-type: text/plain"
print
for i in range(1, 10):
        print i
        sys.stdout.flush()
        time.sleep(1)

print "Done."

perl 中的类似示例:

Similar example in perl:

#!/usr/bin/perl

print "Content-type: text/plain\n\n";

for ($i = 1; $i <= 10 ; $i++) {
        print "$i\n";
        sleep(1);
}

print "Done.";

这个链接说 Apache 1.3 CGI 输出应该是无缓冲的(但这可能只适用于 Apache 1.x):http://httpd.apache.org/docs/1.3/misc/FAQ-F.html#nph-scripts

This link says as of Apache 1.3 CGI output should be unbuffered (but this might apply only to Apache 1.x): http://httpd.apache.org/docs/1.3/misc/FAQ-F.html#nph-scripts

有什么想法吗?

推荐答案

Randal Schwartz 的文章 通过 CGI 观看长进程 解释了观看长时间运行进程的不同(恕我直言,更好)的方式.

Randal Schwartz's article Watching long processes through CGI explains a different (and IMHO, better) way of watching a long running process.

这篇关于如何从 Apache 2 提供无缓冲的 CGI 内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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