hhvm-fastcgi + nginx how to make it display fatal errors in the browser

后端 未结 2 2008
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 23:05

I\'ve been playing with HHVM config file and I have yet to be able to make it output any fatal error to the browser. It displays E_NOTICE and E_WARNING but when any E_ERROR

2条回答
  •  情歌与酒
    2021-01-03 23:45

    Use a custom error handler to handle any type of error exactly the way you want it to. Taken almost directly from example #1 in the link...

    function myErrorHandler($errno, $errstr, $errfile, $errline)
    {
    
        switch ($errno) {
        case E_USER_ERROR:
            echo "My ERROR [$errno] $errstr
    \n"; echo " Fatal error on line $errline in file $errfile"; echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")
    \n"; echo "Aborting...
    \n"; exit(1); break; case E_USER_WARNING: echo "My WARNING [$errno] $errstr
    \n"; break; case E_USER_NOTICE: echo "My NOTICE [$errno] $errstr
    \n"; break; default: echo "Unknown error type: [$errno] $errstr
    \n"; break; } /* Don't execute PHP internal error handler */ return true; } set_error_handler("myErrorHandler");

    For this approach to work, you have to set the error handler as early as possible in your code.

    As you might have noticed I left one bit of code out, namely the one that checks if the error type is configured to be reported in your php/hhvm configuration. With the code above the errors will show regardless of your php/hhvm configuration. (so you probably want to log instead of echo errors in production environment hint)

提交回复
热议问题