Page MenuHomePhabricator

OutputHandler is not initialized depending on PHP.ini settings for output buffering
Open, MediumPublic

Description

Author: wikimedia

Description:
MediaWiki 1.17.0
PHP 5.3.8-1~dotdeb.2 (cgi-fcgi)
MySQL 5.1.58-1~dotdeb.1

In /includes/Webstart.php, starting at line 132:

  1. Initialise output buffering
  2. Check that there is no previous output or previously set up buffers, because
  3. that would cause us to potentially mix gzip and non-gzip output, creating a
  4. big mess.

if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {

		require_once( "$IP/includes/OutputHandler.php" );
		ob_start( 'wfOutputHandler' );

}

The output handler is not initialized if ob_get_level() != 0. As a consequence, gzip content encoding would not be enabled.

The problem is that ob_get_level() will always return 1 or more if you have output buffering enabled in php.ini (output_buffering is false by default, but PHP suggests a production value of 4096), which means that basically every PHP script starts with ob_start().

One solution to this problem would be to remove the default output buffer early when Mediawiki starts:

while(ob_get_level() > 0){

	   ob_end_clean();

}

If this is undesired, and if the conditional check in Webstart is not changed, at the least, mediawiki setup should show a warning notice that with the given output_buffering setting, its output handler (i.e. gzip handler) won't be executed.


Version: 1.21.x
Severity: normal

Details

Reference
bz31342
TitleReferenceAuthorSource BranchDest Branch
Allow setting save_delay to 0repos/mwbot-rs/mwbot!41legoktmzero-save-delaymain
Customize query in GitLab

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 11:54 PM
bzimport set Reference to bz31342.
bzimport added a subscriber: Unknown Object (MLST).

Code has slightly changed /includes/WebStart.php , but still valid in 1.21wmf8:

wfProfileIn( 'WebStart.php-ob_start' );

  1. Initialise output buffering
  2. Check that there is no previous output or previously set up buffers, because
  3. that would cause us to potentially mix gzip and non-gzip output, creating a
  4. big mess.

if ( !defined( 'MW_NO_OUTPUT_BUFFER' ) && ob_get_level() == 0 ) {
if ( !defined( 'MW_COMPILED' ) ) {

		require_once( "$IP/includes/OutputHandler.php" );

}
ob_start( 'wfOutputHandler' );
}

Similar comments in http://stackoverflow.com/questions/3641598/ob-get-level-starts-at-level-1
Docs: http://php.net/manual/en/function.ob-get-level.php