properly stop output buffering
authorAntoine Musso <hashar@free.fr>
Sat, 9 Feb 2013 22:39:43 +0000 (23:39 +0100)
committerAntoine Musso <hashar@free.fr>
Sat, 9 Feb 2013 22:39:43 +0000 (23:39 +0100)
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

index b2bbf9b..a13453d 100644 (file)
@@ -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();
        }