如何在Apache httpd中强制刷新HTTP头?

时间:2016-10-17 21:39:58

标签: apache perl http-headers buffer flush

我需要定期为客户端生成HTTP标头,并且在创建一个标头后,需要将这些标头直接刷新到客户端。我无法等待正文或其他任何东西,我创建了一个标题,我希望Apache httpd将它发送给客户端。

我已经尝试过使用autoflush,手动刷新,8k数据周围的大型标头数据,禁用deflate模块以及可能存在的任何内容,但是httpd似乎忽略了我的愿望,直到所有标头都被创建,之后才开始冲他们。根据我生成头文件的速度,httpd进程甚至会将内存增加到几百兆字节,因此似乎缓冲了所有头文件。

有没有办法让httpd刷新单个标题,还是不可能?

1 个答案:

答案 0 :(得分:0)

The answer is using NPH-scripts, which by default bypass the buffer of the web server. One needs to name the script nph-* and normally a web server should stop buffering headers and send them directly as they are printed and how they are. This works in my case, though using Apache httpd one needs to be careful:

Apache2 sends two HTTP headers with a mapped "nph-" CGI