From 5c9d0c379ec3a7f2f90e7884dffe9870a11a7cf9 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Sat, 9 Feb 2013 23:39:43 +0100 Subject: [PATCH] properly stop output buffering While setting up itself, the Maintenance class attempt flush and end the output buffering mecanism. It was done using a call to ob_end_flush() which has two culprit: - it throws an E_NOTICE whenever output buffering is already disabled - does not flush all buffers By querying ob_get_level() we can find out whether output buffering has been enabled and can thus stop using the '@' operator. Test plan: $ php -a # Output buffering nested level php > print ob_get_level(); 0 # Start buffering php > ob_start(); # Check nesting level (nothing shown since we buffer output) php > print ob_get_level(); # Actually show buffer content php > ob_flush(); 1 # Flush / end, no notice since we were buffering: php > ob_end_flush(); # Second attempt will throw a notice php > ob_end_flush(); Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in php shell code on line 1 Call Stack: 162.3024 643656 1. {main}() php shell code:0 162.3025 643736 2. ob_end_flush() php shell code:1 php > The while( ob_get_level() > 0) solves it nicely (IMO). Change-Id: I1490cced5c17fc537ef9e6e1304a492deec3a6a9 --- maintenance/Maintenance.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/maintenance/Maintenance.php b/maintenance/Maintenance.php index b2bbf9b7b7..a13453df48 100644 --- a/maintenance/Maintenance.php +++ b/maintenance/Maintenance.php @@ -513,8 +513,11 @@ abstract class Maintenance { define( 'MEDIAWIKI', true ); $wgCommandLineMode = true; + # Turn off output buffering if it's on - @ob_end_flush(); + while( ob_get_level() > 0 ) { + ob_end_flush(); + } $this->validateParamsAndArgs(); } -- 2.20.1