选择语言 :

 Core_Core::show_500

系统错误,可直接将Exception对象传给$msg

null Core_Core::show_500( [ string/Exception $msg = null ] )

参数列表

参数 类型 描述 默认值
$msg string/Exception $msg null
File: ./core/classes/core.class.php
public static function show_500($msg = null)
{
    Core::close_buffers(false);

    # 避免输出的CSS头试抛出页面无法显示
    @header('Content-Type: text/html;charset=' . Core::config('core.charset'), true);

    HttpIO::$status = 500;
    HttpIO::send_headers();

    if (null === $msg)
    {
        $msg = __('Internal Server Error');
    }

    if (IS_DEBUG && class_exists('ErrException', false))
    {
        if ($msg instanceof Exception)
        {
            throw $msg;
        }
        else
        {
            throw new Exception($msg, 0);
        }
    }

    if (IS_CLI)
    {
        echo "\x1b[36m";
        if ($msg instanceof Exception)
        {
            echo $msg->getMessage() . CRLF;
        }
        else
        {
            echo $msg . CRLF;
        }

        echo "\x1b[39m";
        echo CRLF;
        exit();
    }

    try
    {
        if ($msg instanceof Exception)
        {
            $error = $msg->getMessage();
            $trace_obj = $msg;
        }
        else
        {
            $error = $msg;
            $trace_obj = new Exception($msg);
        }

        $error_config = Core::config('core.error500');

        $view = new View('error/500');
        if ($error_config && isset($error_config['close']) && $error_config['close']==true)
        {
            # 不记录
            $view->error_saved = false;
        }
        else
        {
            $trace_array = array
            (
                'project'     => Core::$project,
                'uri'         => HttpIO::$uri,
                'url'         => HttpIO::PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"],
                'post'        => HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA),
                'get'         => $_SERVER['QUERY_STRING'],
                'cookie'      => HttpIO::COOKIE(null, HttpIO::PARAM_TYPE_OLDDATA),
                'client_ip'   => HttpIO::IP,
                'user_agent'  => HttpIO::USER_AGENT,
                'referrer'    => HttpIO::REFERRER,
                'server_ip'   => $_SERVER["SERVER_ADDR"],
                'trace'       => $trace_obj->__toString(),
            );

            $date     = @date('Y-m-d');
            $no       = strtoupper(substr(md5(serialize($trace_array)), 10, 10));
            $error_no = $date.'-'.$no;

            # 其它数据
            $trace_array['server_name'] = (function_exists('php_uname')? php_uname('a') : 'unknown');
            $trace_array['time']        = TIME;
            $trace_array['use_time']    = microtime(1) - START_TIME;
            $trace_array['trace']       = $trace_obj;

            $trace_data = base64_encode(gzcompress(serialize($trace_array), 9));
            unset($trace_array);

            $view->error_saved = true;

            # 记录错误日志
            try
            {
                if (isset($error_config['save_type']) && $error_config['save_type'])
                {
                    $save_type = $error_config['save_type'];
                }
                else
                {
                    $save_type = 'file';
                }

                if ($save_type=='file')
                {
                    # 文件模式
                    $write_mode = Core::config('core.file_write_mode');

                    if (preg_match('#^(db|cache)://([a-z0-9_]+)/([a-z0-9_]+)$#i', $write_mode , $m))
                    {
                        $save_type = $m[1];
                        $error_config['type_config'] = $m[2];
                    }
                }

                switch ($save_type)
                {
                    case 'database':
                        $obj = $error_config['type_config']?new Database($error_config['type_config']) : new Database();
                        $data = array
                        (
                            'time'        => strtotime($date.' 00:00:00'),
                            'no'          => $no,
                            'log'         => $trace_data,
                            'expire_time' => TIME + 7*86400,
                        );
                        $obj->insert('error500_log', $data);
                        break;
                    case 'cache':
                        $obj = $error_config['type_config']?new Cache($error_config['type_config']) : new Cache();
                        if (!$obj->get($error_no))
                        {
                            $obj->set($error_no, $trace_data, 7*86400);
                        }
                        break;
                    default:
                        $file = DIR_LOG .'error500'. DS . str_replace('-', DS, $date) . DS . $no . '.log';
                        if (!is_file($file))
                        {
                            File::create_file($file, $trace_data, null, null, $error_config['type_config']?$error_config['type_config']:'default');
                        }
                        break;
                }
            }
            catch (Exception $e)
            {

            }
        }

        $view->error_no = $error_no;
        $view->error = $error;
        $view->render(true);
    }
    catch (Exception $e)
    {
        list ($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
        $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
        echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' .
        CRLF . '<html>' .
        CRLF . '<head>' .
        CRLF . '<title>Internal Server Error</title>' .
        CRLF . '</head>' .
        CRLF . '<body>' .
        CRLF . '<h1>'.__('Internal Server Error').'</h1>' .
        CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' .
        CRLF . '<hr />' .
        CRLF . $_SERVER['SERVER_SIGNATURE'] .
        CRLF . '</body>' .
        CRLF . '</html>';
    }

    exit();
}