/**
  * Get host conf
  */
 protected static function getConfig()
 {
     static $config;
     is_null($config) && ($config = \Frame\ConfigFilter::instance()->getConfig('redis'));
     $nutConfigs = $config['nutHosts'];
     $count = count($nutConfigs);
     $index = rand(0, $count - 1);
     $conf = $nutConfigs[$index];
     empty($conf['host']) && ($conf = array());
     return $conf;
 }
Beispiel #2
0
 protected static function getReadHandle()
 {
     if (!isset(self::$readHandle)) {
         static $config;
         $class = get_called_class();
         is_null($config) && ($config = \Frame\ConfigFilter::instance()->getConfig($class::$configfile));
         $ran = array_rand($config['readHosts']);
         $host = $config['readHosts'][$ran];
         self::$readHandle = new RedisRead($host);
     }
     return self::$readHandle;
 }
 private static function getServiceHost($remote)
 {
     $config = \Frame\ConfigFilter::instance()->getConfig('remote');
     $hosts = NULL;
     if (isset($config[$remote])) {
         $hosts = $config[$remote];
     }
     if (is_array($hosts)) {
         return $hosts[array_rand($hosts)];
     } else {
         return $hosts;
     }
 }
Beispiel #4
0
 /**
  * Constructor.
  */
 protected function __construct()
 {
     is_null($this->config) && ($this->config = \Frame\ConfigFilter::instance()->getConfig('memcache'));
     $this->pools = new \Memcached();
     $this->pools->setOption(\Memcached::OPT_NO_BLOCK, TRUE);
     $this->pools->setOption(\Memcached::OPT_DISTRIBUTION, \Memcached::DISTRIBUTION_CONSISTENT);
     $this->pools->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, TRUE);
     $config = array();
     $unixnum = count($this->config['unixsock']);
     $num = rand(0, $unixnum - 1);
     $weight = 10;
     $config = array();
     $config[] = array($this->config['unixsock'][$num]['host'], $this->config['unixsock'][$num]['port'], $weight);
     $result = $this->pools->addServers($config);
     return TRUE;
 }
Beispiel #5
0
 public function checkLogin()
 {
     if (empty($this->ticket)) {
         return FALSE;
     }
     $this->conf = \Frame\ConfigFilter::instance()->getConfig('passport');
     if (empty($this->conf)) {
         $session = $this->get_session();
     } else {
         $session = $this->get_session_by_api($this->ticket, $this->conf['env']);
     }
     $this->session = $session;
     if (!empty($this->session)) {
         $this->session && $this->session['session_data'] && ($this->session = $this->session['session_data']);
         if ($this->session && $this->session['user_id']) {
             $this->session['login_type'] = 1;
             $this->session['login_from'] = $this->login_from;
             return TRUE;
         }
     }
     return FALSE;
 }
Beispiel #6
0
 private function __construct()
 {
     $this->configs = \Frame\ConfigFilter::instance()->getConfig('db');
 }
 public function __construct()
 {
     $config = \Frame\ConfigFilter::instance()->getConfig('scribe');
     $this->nodes = $config['nodes'];
 }
 private static function collect($file, $str)
 {
     if (!\Frame\ConfigFilter::instance()->getConfig('scribe') || !defined('LOG_COLLECT') || !LOG_COLLECT) {
         return false;
     }
     $collector = new ScribeLogCollector();
     $mark = pathinfo($file, PATHINFO_FILENAME);
     $mark = substr($mark, 0, strpos($file, '.'));
     $str = trim($str);
     try {
         $collector->sendLog($mark, $str);
     } catch (\Exception $e) {
         $strLogFile = dirname(self::getInstance()->strLogFile) . '/logcollect.log.wf' . '.' . date(self::getInstance()->strRotateFormat, time());
         $str = sprintf("COLLECT_ERR: %s ip[%s] logid[%u] uri[%s] %s ||| %s ||| %s\n", date('m-d H:i:s:', time()), self::getClientIP(), self::logId(), isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '', $str, $mark, $e->getMessage());
         @file_put_contents($strLogFile, $str, FILE_APPEND);
     }
 }