private function _initPlugin() { $plugins = Comm_Config::get('app.plugins'); if (!is_array($plugins)) { return; } foreach ($plugins as $plugin) { $this->registerPlugin($plugin); } }
public function onConstruct() { $logDir = Comm_Config::get('app.log_dir'); if (!is_dir($logDir)) { @mkdir($logDir, 0755, true); } // 调用realpath需要目录存在,否则返回false $this->logDir = realpath($logDir); $this->logName = Comm_Config::get('app.name'); $this->logLevel = $this->_strToLevel(Comm_Config::get('app.log_level')); $this->logId = sprintf("%u%04u", substr(sprintf("%.0f", microtime(true) * 1000000), 5), rand(0, 9999)); }
/** * 单例的构造回调,用于初始化 * @return [type] [description] */ public function onConstruct() { if (is_null($this->cacheEnable)) { $this->cacheEnable = Comm_Config::get('cache.enable', true); } if (is_null($this->cacheEngine)) { $this->cacheEngine = Comm_Config::get('cache.engine', 'redis'); } if (!is_null($this->cachePool)) { $this->cache = Comm_Cache::getInstance($this->cachePool, $this->cacheEngine); } if (!is_null($this->dbPool)) { $this->db = Comm_Db::getInstance($this->dbPool); } }
/** * 获取cache实例 * @param [type] $name 配置项名 * @param string $engine 驱动名(null|redis|memcached) * @return [type] [description] */ public static final function getInstance($name, $engine = null) { if (null === $engine) { $engine = Comm_Config::get('cache.engine', 'redis'); } $engine = strtolower($engine); if (empty(self::$_ins[$engine][$name])) { $engineClass = 'Comm_Cache_' . ucfirst($engine); if (!in_array('Comm_Cache', class_parents($engineClass))) { throw new Exception_Base('invalid cache class - ' . $engineClass); } self::$_ins[$engine][$name] = new $engineClass($name); } return self::$_ins[$engine][$name]; }
/** * [__construct description] * @param [type] $params 配置数组或config/redis.php中的配置名 */ public function __construct($params) { if (is_string($params)) { $params = Comm_Config::get("redis.{$params}"); } if (count($params) > 1) { $this->hash = new Comm_Conhash(); } foreach ($params as $svr) { $this->servers[$svr] = null; if ($this->hash) { $this->hash->addNode($svr); } } if (empty($this->servers)) { throw new Exception_Base("redis no server config!"); } }
/** * [__construct description] * @param [type] $params 配置数组或cache.redis中的配置名 */ public function __construct($params) { if (is_string($params)) { $params = Comm_Config::get("cache.redis.{$params}"); } if (count($params) > 1) { $this->hash = new Comm_Conhash(); } foreach ($params as $svr) { $this->servers[$svr] = null; if ($this->hash) { $this->hash->addNode($svr); } } if (empty($this->servers)) { throw new Exception_Base("redis no server config!"); } // 扩展是否支持自动序列化 $this->autoSerialize = defined('Redis::OPT_SERIALIZER'); }
/** * [__construct description] * @param [type] $params 配置数组或cache.memcached.下的配置名 */ public function __construct($params) { if (is_string($params)) { $params = Comm_Config::get("cache.memcached.{$params}"); } $servers = array(); foreach ($params as $svr) { $tmp = explode(':', $svr, 2); $host = empty($tmp[0]) ? '127.0.0.1' : $tmp[0]; $port = empty($tmp[1]) ? 11211 : $tmp[1]; $servers[] = array($host, $port); } if (empty($servers)) { throw new Exception_Base("mc no server config!"); } $this->mc = new Memcached(); $this->mc->setOption(Memcached::OPT_NO_BLOCK, true); $this->mc->setOption(Memcached::OPT_CONNECT_TIMEOUT, self::SOCK_TIMEOUT); $this->mc->setOption(Memcached::OPT_POLL_TIMEOUT, self::SOCK_TIMEOUT); $this->mc->setOption(Memcached::OPT_DISTRIBUTION, Memcached::DISTRIBUTION_CONSISTENT); $this->mc->addServers($servers); }
/** * [__construct description] * @param [type] $params 配置数组或config/db.php中的配置名 */ public function __construct($params) { if (is_string($params)) { $params = Comm_Config::get("db.{$params}"); } $default = array(); $master = array(); $slave = array(); foreach ($params as $key => $val) { if (0 === strpos($key, 'master')) { $master[] = $val; } else { if (0 === strpos($key, 'slave')) { $slave[] = $val; } else { $default[$key] = $val; } } } if (!empty($master)) { $this->masterConfig = $master[array_rand($master)]; } else { if (!empty($default)) { $this->masterConfig = $default; } else { throw new Exception_Base("db config error - {$params}"); } } if (!isset($this->masterConfig['option'][PDO::ATTR_TIMEOUT])) { $this->masterConfig['option'][PDO::ATTR_TIMEOUT] = self::DEFAULT_TIMEOUT; } if (!empty($slave)) { $this->slaveConfig = $slave[array_rand($slave)]; if (!isset($this->slaveConfig['option'][PDO::ATTR_TIMEOUT])) { $this->slaveConfig['option'][PDO::ATTR_TIMEOUT] = self::DEFAULT_TIMEOUT; } } }
private function _initialize() { $class = get_class($this); $this->name = substr(strtolower($class), 0, -6); //去掉daemon后缀 $this->pidFile = Comm_Config::get('app.var_dir') . "/{$this->name}.pid"; $this->outFile = Comm_Config::get('app.var_dir') . "/{$this->name}.out"; if ($this->childNum < self::MIN_CHILD) { $this->childNum = self::MIN_CHILD; } if ($this->childNum > self::MAX_CHILD) { $this->childNum = self::MAX_CHILD; } }