我一直在玩HHVM配置文件,我还没有能够向浏览器输出任何致命错误。它显示E_NOTICE和E_WARNING,但是当发生任何E_ERROR时,它会使页面留空,并且错误仅出现在HHVM日志文件中。
有没有办法让它在浏览器中显示?
我的HHVM配置文件如下:
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;
}
答案 0 :(得分:3)
您需要在hhvm.server.implicit_flush
中启用配置php.ini
,然后您可以在发生致命错误时发送回复正文。为了能够使用错误处理程序捕获致命错误,您还应该启用hhvm.error_handling.call_user_handler_on_fatals
。
有关详细信息,请参阅github issue on hhvm。
答案 1 :(得分:2)
使用custom error handler完全按照您希望的方式处理任何类型的错误。几乎直接来自链接中的示例#1 ...
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");
要使这种方法起作用,您必须尽早在代码中设置错误处理程序。
您可能已经注意到我遗漏了一些代码,即检查错误类型是否配置为在您的php / hhvm配置中报告的代码。使用上面的代码,无论您的php / hhvm配置如何,都会显示错误。 (因此您可能希望在生产环境中记录而不是回显错误提示)