Skip to content

Commit

Permalink
MDL-80275 core: Move disable_output_buffering to setup.php
Browse files Browse the repository at this point in the history
This method is the only reason stopping lib/setuplib.php from being
included after the autoloader and it is single-purposed.
  • Loading branch information
andrewnicols committed May 18, 2024
1 parent a15301b commit 4cbc81c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 39 deletions.
8 changes: 8 additions & 0 deletions lib/deprecatedlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3216,3 +3216,11 @@ function question_fix_top_names() {
function search_generate_text_SQL() {
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
}

/**
* @deprecated Since Moodle 4.5
*/
#[\core\attribute\deprecated('This method should not be used', since: '4.5', mdl: 'MDL-80275', final: true)]
function disable_output_buffering(): void {
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
}
35 changes: 33 additions & 2 deletions lib/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,40 @@
// The httpswwwroot has been deprecated, we keep it as an alias for backwards compatibility with plugins only.
$CFG->httpswwwroot = $CFG->wwwroot;

// We have to call this always before starting session because it discards headers!
if (NO_OUTPUT_BUFFERING) {
// we have to call this always before starting session because it discards headers!
disable_output_buffering();
// Try to disable all output buffering and purge all headers.
$olddebug = error_reporting(0);

// Disable compression, it would prevent closing of buffers.
if ($outputcompression = ini_get('zlib.output_compression')) {
switch(strtolower($outputcompression)) {
case 'on':
case '1':
ini_set('zlib.output_compression', 'Off');
break;
}
}

// Try to flush everything all the time.
ob_implicit_flush(true);

// Close all buffers if possible and discard any existing output.
// This can actually work around some whitespace problems in config.php.
while (ob_get_level()) {
if (!ob_end_clean()) {
// Prevent infinite loop when buffer can not be closed.
break;
}
}

// Disable any other output handlers.
ini_set('output_handler', '');

error_reporting($olddebug);

// Disable buffering in nginx.
header('X-Accel-Buffering: no');
}

// Point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
Expand Down
37 changes: 0 additions & 37 deletions lib/setuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1464,43 +1464,6 @@ function get_real_size($size = 0) {
return (int) $size;
}

/**
* Try to disable all output buffering and purge
* all headers.
*
* @access private to be called only from lib/setup.php !
* @return void
*/
function disable_output_buffering() {
$olddebug = error_reporting(0);

// disable compression, it would prevent closing of buffers
if (ini_get_bool('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}

// try to flush everything all the time
ob_implicit_flush(true);

// close all buffers if possible and discard any existing output
// this can actually work around some whitespace problems in config.php
while(ob_get_level()) {
if (!ob_end_clean()) {
// prevent infinite loop when buffer can not be closed
break;
}
}

// disable any other output handlers
ini_set('output_handler', '');

error_reporting($olddebug);

// Disable buffering in nginx.
header('X-Accel-Buffering: no');

}

/**
* Check whether a major upgrade is needed.
*
Expand Down

0 comments on commit 4cbc81c

Please sign in to comment.