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)
commit5c9d0c379ec3a7f2f90e7884dffe9870a11a7cf9
tree9c76c915b33bf00f6c4f80b3ac77c8c36d33f3b8
parent62a6a48bd4cde140a2bebde73f882754dfaa273b
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