Hi again,

On Tue, Apr 03, 2012 at 02:02:17PM +0200, Bernhard Schmidt wrote:
> > On Thu, Mar 22, 2012 at 03:10:25PM +0000, Bernhard Schmidt wrote:
> >> After upgrading to PHP 5.4 (current wheezy) pnp4nagios displays an 
> >> empty page for all URLs I can think of. There is nothing in the error
> >> log or any other logs I could think of, despite of having all 
> >> error_reporting categories enabled.
> > 
> > Thanks for reporting this! Jörg Linge was able to track this down to a
> > call to ob_end_clean() in Kohana. Apparently, PHP 5.4 handles that
> > function a bit different than earlier versions. Changing that to
> > ob_end_flush() (in case there's something in the buffer) fixes that.
> > 
> > I'm reassigning to Kohana and will upload a fixed version shortly.

> this patch does _not_ work for me. I do get output now, but I get
> everything (the whole page) exactly twice. Completely removing
> ob_end_clean() and not adding anything else fixes the issue for me, but
> I don't know about the disadvantages.

I've just figured that out myself :-/

Removing the line completely will ensure that the page is output just
once but will leave some template variables in place -- see the end of
the page: "Loaded in {execution_time} seconds, ...".

I *suppose* the following happens (but I'm not into PHP at all so some
other feedback would be appreciated):

 - in PHP 5.4, ob_end_clean() no longer passes the buffer to the
   callback function registered using ob_start() but instead passes an
   empty string -> nothing will be displayed

 - when removing ob_end_clean(), the buffer will be flushed
   automatically on shutdown without calling Kohanas render() function
   (not entirely sure why that happens)

 - when replacing ob_end_clean() with ob_end_flush(), the buffer will be
   written out by ob_end_flush() (I suppose) and again by Kohana's
   render()

Apparently, that whole buffer handling / template substitution stuff in
Kohana needs to rewritten to match the new behavior of ob_end_clean().

The following patch seems to work around this problem:

--- a/system/core/Kohana.php
+++ b/system/core/Kohana.php
@@ -691,6 +691,9 @@
                        // Run the send_headers event
                        Event::run('system.send_headers');
                }
+
+        if ("$output" == "")
+            return FALSE;
                
                self::$output   = $output;
                
@@ -719,6 +722,7 @@
                        }
 
                        // Store the Kohana output buffer
+                       self::$output = ob_get_contents();
                        ob_end_clean();
                }
        }

This will make sure that the buffer contents are copied to self::$output
(what used to be done by the registered callback function). Also, the
callback function will not overwrite that variable in case it's passed
an empty buffer. This way, the patch should work with, both, PHP 5.4 and
previous version.

Any comments on that?

TIA,
Sebastian

-- 
Sebastian "tokkee" Harl +++ GnuPG-ID: 0x8501C7FC +++ http://tokkee.org/

Those who would give up Essential Liberty to purchase a little Temporary
Safety, deserve neither Liberty nor Safety.         -- Benjamin Franklin

Attachment: signature.asc
Description: Digital signature

Reply via email to