PHP/Apache 中的输出缓冲块如何工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2072219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How output buffering blocks in PHP/Apache works?
提问by Vladislav Rastrusny
Suppose I am echoing random data from PHP to browser. Total amount of random data is about XGb and echo is done in YKb chunks. ob_start() is not used. Will echo calls block after PHP and Apache buffers are full (client is not capable of consuming data with the same speed it is generated)? If so, how much in size PHP and Apache buffers? Do I understand correctly, the process:
假设我将随机数据从 PHP 回显到浏览器。随机数据总量约为 XGb,回声以 YKb 块完成。ob_start() 没有被使用。PHP 和 Apache 缓冲区已满后,echo 调用是否会阻塞(客户端无法以生成数据的相同速度消耗数据)?如果是这样,PHP 和 Apache 缓冲区的大小是多少?我理解正确吗,过程:
- PHP echo is sending bytes to php output buffer until it is full. After that echo starts to block until some buffer is sent to Apache and thus cleared
- PHP is sending data from it's output buffer until Apache buffer is full. After that Apache stops receiving data from PHP and waits, until part the buffer is sent to client and cleared.
- PHP echo 将字节发送到 php 输出缓冲区,直到它已满。在那个 echo 开始阻塞之后,直到一些缓冲区被发送到 Apache 并因此被清除
- PHP 正在从它的输出缓冲区发送数据,直到 Apache 缓冲区已满。之后 Apache 停止从 PHP 接收数据并等待,直到缓冲区被发送到客户端并被清除。
P.S. If you are suprised by the stupidity of the task I am going to achieve, I can say, that I am writting small traffic balancing script for a dedicatied server with certain traffic rules applied (IN/OUT traffic ratio should be kept at certain value).
PS 如果您对我将要完成的任务的愚蠢感到惊讶,我可以说,我正在为应用了某些流量规则的专用服务器编写小型流量平衡脚本(IN/OUT 流量比率应保持在某个值)。
采纳答案by Artjom Kurapov
This can be related to the SendBufferSizeDirective.
这可能与SendBufferSize指令有关。
Maybe this will help http://fplanque.com/dev/linux/why-echo-is-slow-in-php-how-to-make-it-really-fast
也许这会有所帮助 http://fplanque.com/dev/linux/why-echo-is-slow-in-php-how-to-make-it-really-fast

