Saturday, June 30, 2012

Output Buffering and Default Settings

I recently needed to set up a new development system with Apache and PHP. The last time I configured these two programs was when PHP was at 5.2.x and the ZIP file included a php.ini-development. The most recent version of PHP is 5.4.4 and does not include a php.ini-development.

The PHP application being developed on this system offers a setting for compressing the output for client browsers that support compression. When I turned on this setting, I received this error:

ob_start(): output handler 'ob_gzhandler' conflicts with 'zlib output compression'

Nothing had changed in the PHP application. The only thing that changed was the PHP version. If I were a little less experienced, I may have thought that I found a bug in the latest version of PHP. Instead, I figured that either something had changed in the API and my implementation had been incorrect from the start, or I had something configured wrong.

I compared the php.ini from the old 5.2.x with the php.ini from 5.4.4 and found a difference in the output_buffering setting.

In 5.2.x, the php.ini-development has output_buffering set to Off. In 5.4.4, output_buffering is set to 4096. I set output_buffering to Off and I am no longer receiving the error.