• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed ob_gzhandler Workaround Disables Gzip Compression

thedude

Well-known member
#1
PHP 5.5.7 running on Apache 2.4.7
XenForo 1.2.4

php.ini
zlib.output_compression = On
zlib.output_compression_level = 1
zlib.output_handler not set

I noticed the pages being served by xenforo on my server weren't compressed, so I created a simple test script, ran it off my server and it came back correctly with gzip compression.

after digging into the code, it turns out this chunk of code is preventing my server from compressing pages:

library/XenForo/Application.php
Code:
			// see http://bugs.php.net/bug.php?id=36514
			// and http://xenforo.com/community/threads/53637/
			if (!@ini_get('output_handler'))
			{
				$level = ob_get_level();
				while ($level)
				{
					ob_end_clean();
					$newLevel = ob_get_level();
					if ($newLevel >= $level)
					{
						break;
					}
					$level = $newLevel;
				}
			}
Commenting it out gives me proper compression again
 

Mike

XenForo developer
Staff member
#2
In my testing, I don't actually get compression even with those lines commented out. Looking at the PHP source itself, simply sending a content length header disables zlib.output_compression internally (and we do send a content length by default).

However, I have changed this for 1.3 - zlib compression is effectively disabled for the internal handling. I have only changed this for 1.3 as I want it to go through a beta period to make sure it doesn't cause problems in certain specific configurations.