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

69
February 11, 2019, at 8:50 PM

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

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

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+
Answer 2

Below quotes are taken from the PHP.net manual.

From the introduction page:

The Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has begun outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo and data between blocks of PHP code.

From the runtime configuration page:

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

In php.ini the 0 and 1 values will be translated to booleans, just like 'On' and 'Off'. A different value such as 4096 will be translated into an integer and used as a byte value.

On to your situation

ob_start() will extend the output buffer. This means that the buffer will be outputted when the response is finished or when ob_end_flush() is called.

If you want PHP to output your HTML in chunks, set output_buffering to 0 or OFF.

If you want PHP to buffer before outputting, set it to 1 or any higher number for specific buffer size.

In addition

  • This article gives a more in-depth explanation of the output buffer and it's effects
READ ALSO
How to replace javascript variables with greasemonkey? [on hold]

How to replace javascript variables with greasemonkey? [on hold]

I want to change a variable in javascript with greasemonkey

51
Nodemon not working after updating to version 1.18.10

Nodemon not working after updating to version 1.18.10

nodemon was working perfectly in my mac previously, I updated it to the latest version and when I try to start it, I keep getting the below error

165
ngx-pagination - rendering page very slow

ngx-pagination - rendering page very slow

I am trying to build an application using Nodejs, Angular 6 and SQLIn my database I have more than 80

12
problem with socket programming on my host

problem with socket programming on my host

i wanted to use a website to send some commands to a client app but in my host i can just access to ports 80 and 443 is it possible that i make socket programming with these ports?

70