MDL-80275 core: Move disable_output_buffering to setup.php

This method is the only reason stopping lib/setuplib.php from being
included after the autoloader and it is single-purposed.
This commit is contained in:
Andrew Nicols
2024-05-18 21:03:54 +08:00
parent a15301b69b
commit 4cbc81c7ea
3 changed files with 41 additions and 39 deletions
+8
View File
@@ -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__);
}
+33 -2
View File
@@ -551,9 +551,40 @@ global $SCRIPT;
// 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
-37
View File
@@ -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.
*