Search code examples
phpoutput-buffering

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


What does exactly the value of output_buffering ini variable mean in php.ini? On our older server, it was set to 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

With this, calling ob_clean(); did not have any effect, until I explicitly started the very beginning of my code with ob_start(); (It seems that on the other server with output_buffering=1 it was called implicitly).


Solution

  • 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.

    From the PHP Manual

    What this means is :

    • A value of 0 is false/off so output buffering is disabled.
    • A value of 1 is true/on so that output buffering is enabled and has no set limit (at least in this scope) to the maxmum buffer size.
    • A value of >1 is the maximum number of bytes for a custom output buffer size.

    Therefore, choices above in the PHP.ini config are:

        output_buffering= 0 / 1 / 1+