From bc5d9fb12210c86d20cb4b0d431ba0ebdf470f32 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Thu, 28 Apr 2016 22:22:31 +0200 Subject: [PATCH] Issue #70: Do not try to clean the zlib output compression buffer If you change zlib output compression setting in between ob_start and ob_end_clean or ob_end_flush, you will get a notice: "ob_end_flush() failed to delete buffer zlib output compression". --- code/dispatcher/response/transport/http.php | 13 +++++++++---- code/dispatcher/response/transport/stream.php | 11 ++++++++--- code/exception/handler/abstract.php | 11 ++++++++--- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/code/dispatcher/response/transport/http.php b/code/dispatcher/response/transport/http.php index 0141b8fece..5caf03e70c 100644 --- a/code/dispatcher/response/transport/http.php +++ b/code/dispatcher/response/transport/http.php @@ -69,11 +69,16 @@ public function sendHeaders(DispatcherResponseInterface $response) public function sendContent(DispatcherResponseInterface $response) { //Make sure the output buffers are cleared - $level = ob_get_level(); - while($level > 0) { + foreach(ob_get_status(true) as $status) + { + //Do not try to clear the 'zlib output compression' + //See: https://github.com/timble/kodekit/issues/70 + if($status['name'] == 'zlib output compression') { + break; + } + ob_end_clean(); - $level--; - }; + } echo $response->getStream()->toString(); return $this; diff --git a/code/dispatcher/response/transport/stream.php b/code/dispatcher/response/transport/stream.php index 1170d7773e..38ca472c90 100644 --- a/code/dispatcher/response/transport/stream.php +++ b/code/dispatcher/response/transport/stream.php @@ -194,10 +194,15 @@ public function sendContent(DispatcherResponseInterface $response) } //Make sure the output buffers are cleared - $level = ob_get_level(); - while($level > 0) { + foreach(ob_get_status(true) as $status) + { + //Do not try to clear the 'zlib output compression' + //See: https://github.com/timble/kodekit/issues/70 + if($status['name'] == 'zlib output compression') { + break; + } + ob_end_clean(); - $level--; } $stream = $response->getStream(); diff --git a/code/exception/handler/abstract.php b/code/exception/handler/abstract.php index 2ebe10404a..76f38d4a9d 100644 --- a/code/exception/handler/abstract.php +++ b/code/exception/handler/abstract.php @@ -318,10 +318,15 @@ public function handleException(\Exception $exception) ); //Make sure the output buffers are cleared - $level = ob_get_level(); - while($level > 0) { + foreach(ob_get_status(true) as $status) + { + //Do not try to clear the 'zlib output compression' + //See: https://github.com/timble/kodekit/issues/70 + if($status['name'] == 'zlib output compression') { + break; + } + ob_end_clean(); - $level--; } if (ini_get('display_errors')) {