How can I serve unbuffered CGI content from Apache 2?

人走茶凉 提交于 2019-11-29 04:26:27

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

You must put your push script into a special directory wich contain a special .htaccess with this environnment specs:

Options +ExecCGI
AddHandler cgi-script .cgi .sh .pl .py
SetEnvIfNoCase Content-Type \
"^multipart/form-data;" "MODSEC_NOPOSTBUFFERING=Do not buffer file uploads"
SetEnv no-gzip dont-vary

Flushing STDOUT can help. For example, the following Perl program should work as intended:

#!/usr/bin/perl

use strict;
use warnings;

local $| = 1;

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

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

print "Done.";
Eugene Yokota

According to CGI::Push,

Apache web server from version 1.3b2 on does not need server push scripts installed as NPH scripts: the -nph parameter to do_push() may be set to a false value to disable the extra headers needed by an NPH script.

You just have to find do_push equivalent in python.

Edit: Take a look at CherryPy: Streaming the response body.

When you set the config entry "response.stream" to True (and use "yield") CherryPy manages the conversation between the HTTP server and your code like this:


(source: cherrypy.org)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!