0

我正在尝试使用register_shutdown_function. 我想在调用此函数时显示一个错误页面,如下所示:

`

register_shutdown_function('en795HandleShutdown');
...
function en795HandleShutdown() {
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
echo '  <meta http-equiv="Content-Style-Type" content="text/css"/>';
echo '  <meta http-equiv="Content-Script-Type" content="text/javascript"/>';
echo '  <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />';
echo '  <title>SOMETITLE</title>';
echo '</head>';
echo '<body >';
echo '<div><div>';
echo '      <h1>Error</h1>';
echo '      <h2>Dead End.<h2>';
echo '  </div></div>';
echo '</body>';
echo '</html>';
}

`

我通过在ini_set('max_execution_time', 5);没有数据库的情况下设置和执行来获取Fatal error: Maximum execution time.... 但是当函数被调用时什么都没有发生。我猜出了什么问题。忘了提:ini_set('display_errors', 0);TIA。

4

2 回答 2

0

如果您希望处理致命错误。你最好使用:

http://www.php.net/manual/en/function.set-error-handler.php

链接,是set_error_handler();

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>';
echo '  <meta http-equiv="Content-Style-Type" content="text/css"/>';
echo '  <meta http-equiv="Content-Script-Type" content="text/javascript"/>';
echo '  <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />';
echo '  <title>SOMETITLE</title>';
echo '</head>';
echo '<body >';
echo '<div><div>';
echo '      <h1>Error</h1>';
echo '      <h2>Dead End.<h2>';
echo '  </div></div>';
echo '</body>';
echo '</html>'; 


}


 set_error_handler('myErrorHandler');

register_shutdown_function();当你的脚本完成处理时,在最后执行,所以一旦你的整个脚本完成。您将看到您的“处理程序”

于 2013-03-30T16:59:52.307 回答
0

The answer contributed is wrong for the question. set_error_handler callbacks do not work for fatal errors. For that you must use register_shutdown_function. One way to tell if it is being called when a fatal error occurs is to call error_get_last (http://php.net/manual/en/function.error-get-last.php) and, if it returns an array, check the type if it is E_ERROR.

于 2017-06-13T20:41:51.687 回答