开发者

Errors inside of output buffer

I'm having some problems with the output buffer. I am buffering my script and printing the result using a callback. The problem is that if a error is thrown at any point, nothing is being shown and I am getting a blank screen. I have tried set开发者_StackOverflow中文版ting my own custom error handlers but nothing seems to work. I have a feeling this is because the errors are causing my buffer to call the callback method instead of my error handler. Either that or it's because I have the error handler as a static method, but changing that causes issues elsewhere.

I'd really appreciate any help because this one has me stumped!

public function constructor()
{
    ob_start(array(__CLASS__, 'render'));
    self::$buffer_level = ob_get_level();

    set_error_handler(array(__CLASS__, 'exception_handler'));
    set_exception_handler(array(_CLASS__, 'exception_handler'));

    RUNNING MY SCRIPT HERE

    ob_end_flush();
}

public static function exception_handler($exception, $message = NULL, $file = NULL, $line = NULL)
{
    while (ob_get_level() > self::$buffer_level)
    {
    ob_end_clean();
    }

    echo $exception.' - '.$message.' - '.$file.' - '.$line.'<br/>';
}


I would suggest turning on error logging in PHP which will send errors to the apache error log by default. You could also try turning on track_errors, but I think the log is the best bet. If you don't have access to the apache log, you might have to log things manually.

Log files and tracing strategies are essential when using output buffering and other "behind the scenes" stuff (like ajax).

You might also have a look at the output_buffering setting. See this article: http://thinkpositivesoftware.blogspot.com/2009/03/have-blank-php-page.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜