Example #1
0
 /**
  * Setup the hosts based on the configuration file
  * @throws \Exception
  * @return mixed|void
  */
 public function setup()
 {
     if (empty($this->params['hostGroup'])) {
         $this->params['hostGroup'] = 'default';
     }
     if (empty($this->params['environment'])) {
         $this->params['environment'] = ServerUtility::determineEnvironment();
     }
     if (isset($this->params['timeout'])) {
         $this->timeout = $this->params['timeout'];
     }
     if ($this->params['forceLocalhost']) {
         $this->registerHost('master', '127.0.0.1:6379');
         return;
     }
     $config = $this->getConfig();
     $serverGroups = $config['servergroup'];
     if (!isset($serverGroups[$this->params['hostGroup']])) {
         throw new \Exception('hostgroup is not a valid group setup in the configuration');
     }
     $servers = $serverGroups[$this->params['hostGroup']];
     $this->setMaster($servers);
     $this->setSlaves($servers);
 }
 /**
  * This allows override of how environment information is loaded into this
  * class.
  *
  * @return string
  */
 protected function determineEnvironment()
 {
     return ServerUtility::determineEnvironment();
 }
Example #3
0
 /**
  * Check the table information cache for the given table data
  *
  * @param string $database
  * @param string $table
  * @return string
  */
 public function tableInfo($database, $table)
 {
     // use the mysql registry for this request to look up information about the database/table on this host
     $tableInfo = MysqlTableInfo::getInfo($this->hosts['master'], $database, $table);
     $MemcacheConn = null;
     if ($tableInfo) {
         return $tableInfo;
     }
     $key = current($this->hosts['master']) . "|{$database}.{$table}";
     $isLocal = ServerUtility::isLocal();
     // Using file cache to make thie more portable need to expose caching layer in the future
     CacheManager::setup(array("path" => sys_get_temp_dir()));
     $InstanceCache = CacheManager::Files();
     // when running a local machine we want to allow schema updates to happen at anytime so no caching layer in place
     if ($isLocal) {
         $tableInfo = false;
     } else {
         $tableInfo = $InstanceCache->get($key);
     }
     if (!$tableInfo) {
         $tableInfo = $this->generateSchemaJson($database, $table);
         $InstanceCache->set($key, $tableInfo, $this->tableInfoCacheSec);
         MysqlTableInfo::setInfo($this->hosts['master'], $database, $table, $tableInfo);
     }
     return $tableInfo;
 }