PHP和Apache prevent输出缓冲 [英] Prevent output buffering with PHP and Apache

查看:129
本文介绍了PHP和Apache prevent输出缓冲的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,发送大量的记录,我想尽快冲洗每个记录,因为它是可用:客户端能够处理每个记录,因为它到达时,它并不需要等待整个响应。我知道这对于整个传输,因为它需要多个数据包被发送的时间会稍长,但它仍然允许客户机开始工作越快。

I have a PHP script which sends a large number of records, and I want to flush each record as soon as it is available: the client is able to process each record as it arrives, it does not need to wait for the entire response. I realize it takes slightly longer for the entire transfer because it needs to be sent in multiple packets, but it still allows the client to start working sooner.

我已经尝试了各种不同的刷新()使用ob_flush()功能,但似乎没有任何帮助获得数据的页完成之前通过线路实际发送。我已经证实了它是不是网页浏览器,因为我使用telnet进行了测试。

I've tried all the different flush() and ob_flush() functions but nothing seems to help get the data actually sent over the line before the page is finished. I've confirmed that it is not the web browser because I've tested it using telnet.

推荐答案

这工作对我来说,唯一的解决办法是将 output_buffering 指令在php.ini为Off 。我不想整个服务器,仅这一个特定的资源做到这一点。通常情况下,你可以使用的ini_set 从PHP脚本,但无论出于何种原因PHP不允许 output_buffering 中设置这种方式(请参见 PHP手册)。

The only solution that worked for me was to set the output_buffering directive in php.ini to "Off". I didn't want to do this for the entire server, just this one specific resource. Normally you could use ini_set from the PHP script, but for whatever reason php doesn't allow output_buffering to be set in this way (see the php manual).

那么事实证明,如果你使用Apache,你可以设置一些PHP INI指令(包括 output_buffering )从你的服务器配置,包括.htaccess文件。所以我用的.htaccess文件以下禁用output_buffering只是一个文件:

Well it turns out that if you're using Apache, you can set some php ini directives (including output_buffering) from your server config, including a .htaccess file. So I used the following in a .htaccess file to disable the output_buffering just for that one file:

<Files "q.php">
    php_value output_buffering Off
</Files>

然后在我的静态服务器配置,我只是需要的AllowOverride选项= php_value (或一个较大的锤子,如的AllowOverride全部)在.htaccess文件被允许的。

And then in my static server configuration, I just needed AllowOverride Options=php_value (or a larger hammer, like AllowOverride All) in order for that to be allowed in a .htaccess file.

这篇关于PHP和Apache prevent输出缓冲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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