該文是wecenter學(xué)習(xí)筆記的一部分
全局異常處理
通過設(shè)置全局異炒遥回調(diào),將錯(cuò)誤定向到500頁面
system/aws_app.inc.php#init
set_exception_handler(array('AWS_APP', 'exception_handle'));
...
public static function exception_handle($exception)
{
$exception_message = "Application error\n------\nMessage: " . $exception->getMessage() . "\nFile: " . $exception->getFile() . "\nLine: " . $exception->getLine() . "\n------\nBuild: " . G_VERSION . " " . G_VERSION_BUILD . "\nPHP Version: " . PHP_VERSION . "\nURI: " . $_SERVER['REQUEST_URI'] . "\nUser Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\nAccept Language: " . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . "\nIP Address: " . fetch_ip() . "\n------\n" . $exception->getTraceAsString();
show_error($exception_message, $exception->getMessage());
}
system/functions.inc.php
function show_error($exception_message, $error_message = '')
{
@ob_end_clean();
if (get_setting('report_diagnostics') == 'Y' AND class_exists('AWS_APP', false))
{
AWS_APP::mail()->send('wecenter_report@wecenter.com', '[' . G_VERSION . '][' . G_VERSION_BUILD . '][' . base_url() . ']' . $error_message, nl2br($exception_message), get_setting('site_name'), 'WeCenter');
}
if (isset($_SERVER['SERVER_PROTOCOL']) AND strstr($_SERVER['SERVER_PROTOCOL'], '/1.0') !== false)
{
header("HTTP/1.0 500 Internal Server Error");
}
else
{
header("HTTP/1.1 500 Internal Server Error");
}
echo _show_error($exception_message);
exit;
}
發(fā)生未處理異常時(shí)會(huì)給wecenter發(fā)郵件躁劣,不需要這個(gè)行為可以關(guān)閉掉report_diagnostics
設(shè)置項(xiàng)