php.ini 中 output_buffering 的值 1 和 4096 有什么区别

What is the difference between values 1 and 4096 of output_buffering in php.ini

在 php.ini 中 output_buffering ini 变量的值究竟意味着什么? 在我们的旧服务器上,它被设置为 1

output_buffering = 1

With this setting, I could call ob_clean(); and it worked like a charm. However, we moved our system to a new server where the output buffering was set to 4096:

output_buffering = 4096

有了这个,调用 ob_clean(); 没有任何效果,直到我明确地用 ob_start(); 开始我的代码的开头(似乎在另一台服务器上用 output_buffering =1 它被隐式调用了)。

output_buffering boolean/integer

You can enable output buffering for all files by setting this directive to 'On'. If you wish to limit the size of the buffer to a certain size - you can use a maximum number of bytes instead of 'On', as a value for this directive (e.g., output_buffering=4096). This directive is always Off in PHP-CLI.

来自the PHP Manual

这意味着:

  • 0 的值为 false/off,因此输出缓冲被禁用。
  • 1 的值是 true/on,因此输出缓冲已启用并且没有设置限制(至少在此范围内)最大缓冲区大小。
  • >1 的值是自定义输出缓冲区大小的最大字节数。

因此,PHP.ini 配置中的上述选择是:

    output_buffering= 0 / 1 / 1+