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

2

18

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 happens it leaves the page blank and the error only appears in the HHVM log file.

Is there a way to make it show in the browser?

My HHVM config file is as follow:

PidFile = /var/run/hhvm/pid

Log {
  Level = Warning
  AlwaysLogUnhandledExceptions = true
  RuntimeErrorReportingLevel = 8191
  UseLogFile = true
  UseSyslog = false
  File = /var/log/hhvm/error.log
  InjectedStackTrace = false
  NativeStackTrace = false
  Access {
    * {
      File = /var/log/hhvm/access.log
      Format = %h %l %u % t \"%r\" %>s %b
    }
  }
}

ErrorHandling {
  CallUserHandlerOnFatals = true
  NoInfiniteLoopDetection = false
  NoInfiniteRecursionDetection = false
  ThrowBadTypeExceptions = false
  ThrowNotices = false
  NoticeFrequency = 1    # 1 out of these many notices to log
  WarningFrequency = 1   # 1 out of these many warnings to log
  AssertActive = false
  AssertWarning = false
}

Debug {
  FullBacktrace = false
  ServerStackTrace = false
  ServerErrorMessage = false
  TranslateSource = false

  RecordInput = false
  ClearInputOnSuccess = true

  ProfilerOutputDir = /tmp

  CoreDumpReport = true
  CoreDumpReportDirectory = /tmp
}

Http {
  DefaultTimeout = 30 # in seconds
  SlowQueryThreshold = 5000 # in ms, log slow HTTP requests as errors
}

Mail {
  SendmailPath = sendmail -t -i
  ForceExtraParameters =
}

Preg {
 BacktraceLimit = 100000
 RecursionLimit = 100000
}

Repo {
  Central {
    Path = /var/log/hhvm/.hhvm.hhbc
  }
}

Eval {
  Jit = true
}

MySQL {
  TypedResults = false
  ReadOnly = false
  ConnectTimeout = 2000      # in ms
  ReadTimeout = 2000         # in ms
  SlowQueryThreshold = 2000  # in ms, log slow queries as errors
  KillOnTimeout = false
}

Nginx:

location ~ \.php$ {
    fastcgi_keep_conn on;

    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    fastcgi_read_timeout 900;
    fastcgi_send_timeout 900;
    fastcgi_intercept_errors off;

    fastcgi_pass   127.0.0.1:9000;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}
Prem answered 15/4, 2014 at 14:37 Comment(6)
I've also tried with Debug { FullBacktrace = true ServerStackTrace = true ServerErrorMessage = true TranslateSource = true } and even if some information shows up the file and line information does not show.Prem
How about the PHP end? have you enabled displaying all errors?Borries
Thank you for your reply. Yes at the PHP end I have error_reporting(E_ALL); and ini_set('display_errors', 1);. As I said it is only the E_ERROR that I'm not getting.Prem
can you please share with us an example of your code as well? any code sample that can result in the fault.Borries
For example calling a function that does not exist.Prem
I have the same problem, tried all options I could find. Also fastscgi + nginx. How can I investigate this further?Ineradicable
A
3

You need to enable the configuration hhvm.server.implicit_flush in your php.ini, then you can send a response body in case of fatal errors. To be able to catch fatal errors with an error handler, you should also enable hhvm.error_handling.call_user_handler_on_fatals.

For details, refer to the github issue on hhvm.

Armendariz answered 17/2, 2015 at 20:17 Comment(0)
N
2

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 "<b>My ERROR</b> [$errno] $errstr<br />\n";
        echo "  Fatal error on line $errline in file $errfile";
        echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
        echo "Aborting...<br />\n";
        exit(1);
        break;

   case E_USER_WARNING:
        echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
        break;

    case E_USER_NOTICE:
        echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
        break;

    default:
        echo "Unknown error type: [$errno] $errstr<br />\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)

Nobell answered 3/1, 2015 at 17:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.