/** * 框架初始化 */ public static function init() { spl_autoload_register('Core::autoLoad'); if (!defined('CORE_FUNCTION') && !@(include FW_PATH . 'func.php')) { exit('func.php is missing'); } if (!defined('CUSTOM_FUNCTION') && !@(include FW_PATH . 'custom.php')) { exit('custom.php is missing'); } if (C('config', 'debug', false)) { define('IS_DEBUG', true); error_reporting(E_ALL); } else { define('IS_DEBUG', false); error_reporting(0); } set_error_handler('Core::_errorHandle', error_reporting()); set_exception_handler('Core::_exceptionHandle'); register_shutdown_function('Core::_shutdownHandle'); if (function_exists('date_default_timezone_set')) { @date_default_timezone_set(C('config', 'timezone', 'Etc/GMT-8')); } define('TIME', time()); define('IP', Base_Request::get_client_ip()); define('CHARSET', C('config', 'charset', 'UTF-8')); define('PHP_FILE', Base_Request::get_script_url()); define('SCRIPT_NAME', basename(PHP_FILE)); define('WEB_PATH', substr(PHP_FILE, 0, strrpos(PHP_FILE, '/')) . '/'); mb_internal_encoding(CHARSET); if (MAGIC_QUOTES_GPC) { $_POST = String::stripslashes($_POST); $_GET = String::stripslashes($_GET); $_COOKIE = String::stripslashes($_COOKIE); $_REQUEST = String::stripslashes($_REQUEST); } if (isset($_GET['page'])) { $_GET['page'] = max(intval($_GET['page']), 1); } if (!IS_CLI) { /* 协议 */ define('SITE_PROTOCOL', Base_Request::get_scheme() . '://'); /* 主机名 */ define('SITE_HOST', Base_Request::get_server_name()); /* 基础URL */ define('SITE_URL', htmlspecialchars(Base_Request::get_base_url(true)) . '/'); /* 设置来源 */ define('HTTP_REFERER', Base_Request::get_url_referer()); define('REQUEST_METHOD', Base_Request::get_request_method()); define('IS_GET', Base_Request::is_get()); define('IS_POST', Base_Request::is_post()); define('IS_PUT', Base_Request::is_put()); define('IS_DELETE', Base_Request::is_delete()); define('IS_AJAX', Base_Request::is_ajax()); @header('Content-Type: text/html; charset=' . CHARSET); @header('X-Powered-By: PHP/' . PHP_VERSION . ' Leaps/' . LEAPS_VERSION); // 页面压缩输出支持 if (C('config', 'gzip', true) && function_exists('ob_gzhandler')) { ob_start('ob_gzhandler'); } else { ob_start(); } } }
function show_trace() { if (!Base_Request::is_ajax() && C('config', 'show_trace')) { $trace_page_tabs = array('BASE' => '基本', 'FILE' => '文件', 'INFO' => '流程', 'ERR|NOTIC' => '错误', 'SQL' => 'SQL', 'DEBUG' => '调试'); // 页面Trace可定制的选项卡 // 系统默认显示信息 $files = get_included_files(); $info = array(); foreach ($files as $key => $file) { $info[] = $file . ' ( ' . number_format(filesize($file) / 1024, 2) . ' KB )'; } $trace = array(); $base = array('请求信息' => date('Y-m-d H:i:s', $_SERVER['REQUEST_TIME']) . ' ' . $_SERVER['SERVER_PROTOCOL'] . ' ' . $_SERVER['REQUEST_METHOD'] . ' : ' . $_SERVER['REQUEST_URI'], '运行时间' => show_time(), '内存开销' => MEMORY_LIMIT_ON ? number_format((memory_get_usage() - START_MEMORY) / 1024, 2) . ' kb' : '不支持', '查询信息' => N('db_query') . ' queries ' . N('db_write') . ' writes ', '文件加载' => count(get_included_files()), '缓存信息' => N('cache_read') . ' gets ' . N('cache_write') . ' writes ', '会话信息' => 'SESSION_ID=' . session_id()); $debug = trace(); foreach ($trace_page_tabs as $name => $title) { switch (strtoupper($name)) { case 'BASE': // 基本信息 $trace[$title] = $base; break; case 'FILE': // 文件信息 $trace[$title] = $info; break; default: // 调试信息 $name = strtoupper($name); if (strpos($name, '|')) { // 多组信息 $array = explode('|', $name); $result = array(); foreach ($array as $name) { $result += isset($debug[$name]) ? $debug[$name] : array(); } $trace[$title] = $result; } else { $trace[$title] = isset($debug[$name]) ? $debug[$name] : ''; } } } } include FW_PATH . 'errors' . DIRECTORY_SEPARATOR . 'trace.php'; }