2014-04-15 43 views
18

我一直在玩HHVM配置文件,我還沒有能夠讓它向瀏覽器輸出任何致命錯誤。它顯示E_NOTICE和E_WARNING,但是當發生任何E_ERROR時,它將頁面留空並且錯誤只出現在HHVM日誌文件中。hhvm-fastcgi + nginx如何讓它在瀏覽器中顯示致命錯誤

有沒有辦法讓它在瀏覽器中顯示?

我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

我也試圖與 調試{ FullBacktrace =真 ServerStackTrace =真 ServerErrorMessage =真 TranslateSource =真 } 即使一些信息顯示了__FILE__和__LINE__信息不顯示。 – Satake

+0

PHP結束如何?你有沒有啓用顯示所有錯誤? – Sina

+0

謝謝你的回覆。是的在PHP結束我有\t \t \t error_reporting(E_ALL);和ini_set('display_errors',1);.正如我所說,這只是E_ERROR,我沒有得到。 – Satake

回答

2

您需要啓用配置hhvm.server.implicit_flushphp.ini,那麼您可以在致命錯誤的情況下發送響應體。爲了能夠使用錯誤處理程序捕捉致命錯誤,還應該啓用hhvm.error_handling.call_user_handler_on_fatals

有關詳細信息,請參閱github issue on hhvm

1

使用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配置如何,錯誤都會顯示。 (所以你可能要改爲登錄回聲錯誤的生產環境提示