/** * 系统初始化 */ private static function init() { set_exception_handler(array('AWS_APP', 'exception_handle')); self::$config = load_class('core_config'); self::$db = load_class('core_db'); self::$plugins = load_class('core_plugins'); self::$settings = self::model('setting')->get_settings(); if ((!defined('G_SESSION_SAVE') or G_SESSION_SAVE == 'db') and get_setting('db_version') > 20121123) { Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable(array('name' => get_table('sessions'), 'primary' => 'id', 'modifiedColumn' => 'modified', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime'))); self::$session_type = 'db'; } Zend_Session::setOptions(array('name' => G_COOKIE_PREFIX . '_Session', 'cookie_domain' => G_COOKIE_DOMAIN)); if (G_SESSION_SAVE == 'file' and G_SESSION_SAVE_PATH) { Zend_Session::setOptions(array('save_path' => G_SESSION_SAVE_PATH)); } Zend_Session::start(); self::$session = new Zend_Session_Namespace(G_COOKIE_PREFIX . '_Anwsion'); if ($default_timezone = get_setting('default_timezone')) { date_default_timezone_set($default_timezone); } if ($img_url = get_setting('img_url')) { define('G_STATIC_URL', $img_url); } else { define('G_STATIC_URL', base_url() . '/static'); } if (self::config()->get('system')->debug) { if ($cornd_timer = self::cache()->getGroup('crond')) { foreach ($cornd_timer as $cornd_tag) { if ($cornd_runtime = self::cache()->get($cornd_tag)) { AWS_APP::debug_log('crond', 0, 'Tag: ' . str_replace('crond_timer_', '', $cornd_tag) . ', Last run time: ' . date('Y-m-d H:i:s', $cornd_runtime)); } } } } }
/** * 切换到从数据库 * * 此功能用于数据库主从分离 * * @return object */ public function slave() { if (!AWS_APP::config()->get('database')->slave or $this->_current_db == 'slave') { return $this; } if (AWS_APP::config()->get('system')->debug) { $start_time = microtime(TRUE); } AWS_APP::db('slave'); if (AWS_APP::config()->get('system')->debug) { AWS_APP::debug_log('database', microtime(TRUE) - $start_time, 'Slave DB Seleted'); } return $this; }