php ini output_buffering

Anybody with even minimal PHP experience is likely quite familiar with the following two messages:

"Cannot add header information headers already sent"
"Oops, php_set_cookie called after header has been sent"

These messages occur when a script attempts to modify a header after it has already been sent back to the requesting user. Most commonly they are the result of the programmer attempting to send a cookie to the user after some output has already been sent back to the browser, which is impossible to accomplish because the header (not seen by the user, but used by the browser) will always precede that output.

PHP version 4.0 offered a solution to this annoying problem by introducing the concept of output buffering When enabled, output buffering tells PHP to send all output at once, after the script has been completed. This way, any subsequent changes to the header can be made throughout the script because it hasn't yet been sent.

Note: Output buffering can also be controlled via Output Buffering Control functions.Possible Values:

On = Enabled and buffer is unlimited. (Use with caution)
Off = Disabled
Integer = Enables the buffer and sets its maximum size in bytes.

Note: This directive is hardcoded to Off for the CLI SAPI

; Default Value: Off
; Development Value: 4096
; Production Value: 4096
output_buffering = Off

Enabling the output_buffering directive turns output buffering on. Alternatively, you can limit the size of the output buffer (thereby implicitly enabling output buffering) by setting it to the maximum number of bytes you'd like this buffer to contain.

If you do not plan to use output buffering, you should disable this directive because it will hinder performance slightly. Of course, the easiest solution to the header issue is simply to pass the information before any other content whenever possible.





Content