From 1572de60a0535425fc582a971a51899ce7548252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=BC=E5=90=B8=E4=BA=8C=E6=B0=A7=E5=8C=96=E7=A2=B3?= Date: Thu, 24 Jan 2013 23:31:50 +0800 Subject: [PATCH] =?UTF-8?q?core=E7=B1=BB=E5=BA=93=E6=9B=B4=E6=96=B0Core::c?= =?UTF-8?q?hange=5Fproject()=E6=96=B9=E6=B3=95=20Bootstrap=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E8=BD=BD=E5=85=A5=E7=B1=BB=E5=BA=93=E7=9A=84=20index.?= =?UTF-8?q?php=E5=AE=8C=E5=96=84=E8=AF=B4=E6=98=8E=20config.new.php?= =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=AF=B4=E6=98=8E=20welcome.view.php?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.new.php | 35 +++++++++++++++---- core/bootstrap.php | 18 ++++++---- core/classes/core.class.php | 41 +++++++++++++--------- index.php | 46 +++++++++++++++++++++---- projects/default/views/welcome.view.php | 6 ++-- 5 files changed, 107 insertions(+), 39 deletions(-) diff --git a/config.new.php b/config.new.php index c1ec798..f795f68 100644 --- a/config.new.php +++ b/config.new.php @@ -3,19 +3,41 @@ * 项目配置 * * 建议将default项目放在最后面 - * url 可以是字符串也可以是数组,可以/开头,也可以http://开头。结尾不需要加/ * * @var array */ $config['projects'] = array ( + // 请在这边加入其它项目,参照default + /* + 'admin' => array + ( + 'name' => '独立后台', + 'dir' => 'admin', + 'isuse' => true, + 'url' => '/admin/', + 'url_admin' => '/', + ), + */ + + // 请确保Default放在最后 'default' => array ( - 'name' => '默认项目', - 'isuse' => true, - 'dir' => 'default', - 'url' => '/', - 'url_admin' => '/admin/', + 'name' => '默认项目', //名称 + 'dir' => 'default', //目录 + 'isuse' => true, //是否启用 + 'url' => '/', //URL根目录,可以是字符串也可以是数组,可以/开头,也可以http://开头。 + 'url_admin' => '/admin/', //后台URL根目录,同上 + /* + // 此项目有的加载类库配置 + 'libraries' => array + ( + 'autoload' => array(), + 'cli' => array(), + 'debug' => array(), + 'admin' => array(), + ), + */ ), ); @@ -157,6 +179,7 @@ /** * 语言包 + * * @var string */ $config['lang'] = 'zh-cn'; diff --git a/core/bootstrap.php b/core/bootstrap.php index d6cc610..d6f685a 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -402,7 +402,7 @@ public static function setup($auto_execute = true) # 读取配置 if ( !is_file(DIR_SYSTEM.'config'.EXT) ) { - self::_show_error( __('Please rename the file config.new:EXT to config:EXT' , array(':EXT'=>EXT)) ); + self::_show_error(__('Please rename the file config.new:EXT to config:EXT', array(':EXT'=>EXT))); } __include_config_file(self::$core_config, DIR_SYSTEM.'config'.EXT); @@ -487,7 +487,7 @@ public static function setup($auto_execute = true) if (!isset(self::$core_config['projects'][$project])) { - self::_show_error( __('not found the project: :project',array(':project'=>$project)) ); + self::_show_error(__('not found the project: :project', array(':project'=>$project))); } // 如果有设置项目 @@ -536,6 +536,11 @@ public static function setup($auto_execute = true) } } + if ( isset(self::$core_config['projects'][self::$project]['isuse']) && !self::$core_config['projects'][self::$project]['isuse'] ) + { + self::_show_error(__('the project: :project is not open.' , array(':project'=>$project))); + } + /** * 初始项目名 * @@ -562,7 +567,7 @@ public static function setup($auto_execute = true) if (!is_dir($project_dir)) { - self::_show_error('not found the project: :project', array(':project' => self::$project)); + self::_show_error(__('not found the project: :project', array(':project' => self::$project))); } self::$include_path['project'] = array($project_dir); @@ -1195,9 +1200,10 @@ public static function protocol() protected static function reload_all_libraries() { # 加载类库 + $lib_config = self::$core_config['libraries']; foreach (array('autoload', 'cli', 'admin', 'debug') as $type) { - if (!isset(self::$core_config['libraries'][$type]) || !self::$core_config['libraries'][$type])continue; + if (!isset($lib_config[$type]) || !$lib_config[$type])continue; if ($type=='cli') { @@ -1212,7 +1218,7 @@ protected static function reload_all_libraries() if (!IS_DEBUG)continue; } - $libs = array_reverse((array)self::$core_config['libraries'][$type]); + $libs = array_reverse((array)$lib_config[$type]); foreach ($libs as $lib) { self::_add_include_path_lib($lib); @@ -1226,7 +1232,7 @@ protected static function reload_all_libraries() $include_path = array_reverse(self::include_path()); foreach ($include_path as $path) { - $config_file = $path.'config'.EXT; + $config_file = $path . 'config' . EXT; if ( is_file($config_file) ) { diff --git a/core/classes/core.class.php b/core/classes/core.class.php index d549334..0a8bdb3 100644 --- a/core/classes/core.class.php +++ b/core/classes/core.class.php @@ -1104,29 +1104,26 @@ public static function change_project($project) ); } - # 设为当前项目 - Core::$project = $project; - - # 记录debug信息 - if (IS_DEBUG) - { - Core::debug()->info($project, '程序已切换到了新项目'); - } - if ( isset($all_prjects_setting[$project]) ) { + # 设为当前项目 + Core::$project = $project; + # 还原配置 Core::$config = $all_prjects_setting[$project]['config']; Core::$include_path = $all_prjects_setting[$project]['include_path']; Core::$file_list = $all_prjects_setting[$project]['file_list']; Core::$project_dir = $all_prjects_setting[$project]['project_dir']; Core::$base_url = $all_prjects_setting[$project]['base_url']; + + # 清除缓存数据 + unset($all_prjects_setting[$project]); } else { - $core_config = Core::$core_config; + $p_config = Core::$core_config['projects'][$project]; - if (!isset($core_config['projects'][$project]['dir']) || !$core_config['projects'][$project]['dir']) + if (!isset($p_config['dir']) || !$p_config['dir']) { Core::show_500(__('the project ":project" dir is not defined.', array(':project'=>$project))); } @@ -1139,20 +1136,24 @@ public static function change_project($project) } # 项目路径 - $project_dir = realpath(DIR_PROJECT . $core_config['projects'][$project]['dir']); + $project_dir = realpath(DIR_PROJECT . $p_config['dir']); if (!$project_dir || !is_dir($project_dir)) { - Core::show_500(__('the project dir :dir is not exist.', array(':dir'=>$core_config['projects'][$project]['dir']))); + Core::show_500(__('the project dir :dir is not exist.', array(':dir'=>$p_config['dir']))); } + # 设为当前项目 + Core::$project = $project; + $project_dir .= DS; + Core::$project_dir = $project_dir; # 处理base_url - if ( isset($core_config['projects'][$project]['url']) && $core_config['projects'][$project]['url'] ) + if ( isset($p_config['url']) && $p_config['url'] ) { - $url = rtrim(current((array)$core_config['projects'][$project]['url']),'/'); + $url = rtrim(current((array)$p_config['url']),'/'); } else { @@ -1161,9 +1162,9 @@ public static function change_project($project) if (IS_ADMIN_MODE) { - if (isset($core_config['projects'][$project]['url_admin']) && $core_config['projects'][$project]['url_admin']) + if (isset($p_config['url_admin']) && $p_config['url_admin']) { - $admin_url = current((array)$core_config['projects'][$project]['url_admin']); + $admin_url = current((array)$p_config['url_admin']); if (false===strpos($admin_url[0],'://')) { $url .= trim($admin_url,'/'); @@ -1181,6 +1182,12 @@ public static function change_project($project) Core::reload_all_libraries(); } + # 记录debug信息 + if (IS_DEBUG) + { + Core::debug()->info($project, '程序已切换到了新项目'); + } + return true; } diff --git a/index.php b/index.php index cb757d2..f5f767b 100644 --- a/index.php +++ b/index.php @@ -2,11 +2,22 @@ @chdir(dirname(__FILE__)); /** - * 数据目录,支持网络协议格式 + * 负载保护值,0表示不启用 + * 不支持window系统 * - * ftp://host:port/dir/ - * redis://127.0.0.1/test/ - * mysql://root:123456@127.0.0.1/test/ + * 建议最大负载不要超过3*N核,例如有16核(含8核超线程)则 16*3=48 + * + * @var int + */ +$max_load_avg = 48; + +/** + * 数据目录,默认为文件目录,支持数据库,缓存,可用于类似BAE,SAE,SEE,ACE等目录无写权限的环境 + * + * PS:如果是希望保存到redis里,可使用 cache://redis/ 然后在config中配置一个$config['cache']['redis']的配置 + * + * db://default/test //表示用配置为default数据库保存,表名称为test + * cache://test/abc //表示用缓存配置为test的保存,数据前缀为 abc * * @var string * @see http://www.myqee.com/docs/config/index_page/ @@ -30,6 +41,26 @@ + + + + + + + + + + + + + + + +////////////////////////////////////////////////////////////////以下无需修改 + + + + /** * 服务器负载保护函数,本方法目前不支持window系统 * @@ -37,9 +68,9 @@ * * @see http://php.net/manual/en/function.sys-getloadavg.php */ -function _load_protection($max_load_avg=24) +function _load_protection() { - global $dir_log,$dir_wwwroot; + global $dir_log,$dir_wwwroot,$max_load_avg; if ( !function_exists('sys_getloadavg') ) { return false; @@ -87,7 +118,8 @@ function _load_protection($max_load_avg=24) exit( file_get_contents( $dir_wwwroot.'errors/server_overload.html') ); } -_load_protection(); +// 执行负载保护脚本 +if ($max_load_avg>0)_load_protection(); // 是否直接执行Core::run(); diff --git a/projects/default/views/welcome.view.php b/projects/default/views/welcome.view.php index 0b6e525..1cb2503 100644 --- a/projects/default/views/welcome.view.php +++ b/projects/default/views/welcome.view.php @@ -240,13 +240,13 @@ - Global目录: + Team类库目录: - + - 第三方类库目录: + 第三方开源类库目录: