简体   繁体   English

输出缓冲区内的错误

[英]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 setting 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. 我建议在PHP中打开错误日志记录,默认情况下会将错误发送到apache错误日志。 You could also try turning on track_errors, but I think the log is the best bet. 您也可以尝试打开track_errors,但我认为日志是最好的选择。 If you don't have access to the apache log, you might have to log things manually. 如果您无权访问apache日志,则可能必须手动记录。

Log files and tracing strategies are essential when using output buffering and other "behind the scenes" stuff (like ajax). 使用输出缓冲和其他“幕后”东西(例如ajax)时,日志文件和跟踪策略至关重要。

You might also have a look at the output_buffering setting. 您还可以查看output_buffering设置。 See this article: http://thinkpositivesoftware.blogspot.com/2009/03/have-blank-php-page.html 看到这篇文章: http : //thinkpositivesoftware.blogspot.com/2009/03/have-blank-php-page.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM