1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * 监控配置中心
- */
- require_once(dirname(__FILE__) .'/../extensions/apollo/ApolloClient.php');
- class ApolloConfigMonitorCommand extends CConsoleCommand {
- public $server; //指定apollo的服务地址
- public $appId;
- public $cluster; //配置中心集群,对应本地环境
- public $nameSpaces=array(); //指定要拉取哪些namespace的配置
- public function init() {
- parent::init();
-
- @ini_set('memory_limit', '1024M');
- set_time_limit(0);
- }
-
- public function actionIndex($YII_ENV='development'){
- //读取apollo配置
- $mainConfig=require dirname(__FILE__) .'/../config/main.'. $YII_ENV .'.php';
- $this->server=$mainConfig['params']['apollo']['server'];
- $this->appId=$mainConfig['params']['apollo']['appId'];
- $this->cluster=$YII_ENV; //配置中心集群,对应本地环境
- //集群
- if ($YII_ENV == 'development') {
- $this->cluster = 'dev';
- }
- //集群
- if ($YII_ENV == 'production') {
- $this->cluster = 'default';
- }
- $this->nameSpaces = $mainConfig['params']['apollo']['nameSpace'];
- //配置文件存储路径
- $configFile=dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'cache';
- //公共配置路径
- $publicConfigPath = dirname(__FILE__) .'/../config/';
- $apollo = new ApolloClient($this->server, $this->appId, $this->nameSpaces,$this->cluster,$configFile,$publicConfigPath);
- $apollo->start();
- }
- //读取Yaml格式配置
- public function actionTask($YII_ENV='development'){
- //读取apollo配置
- $mainConfig=require dirname(__FILE__) .'/../config/main.'. $YII_ENV .'.php';
- $this->server=$mainConfig['params']['apolloYaml']['server'];
- $this->appId=$mainConfig['params']['apolloYaml']['appId'];
- $this->cluster=$YII_ENV; //配置中心集群,对应本地环境
- //集群
- if ($YII_ENV == 'production') {
- $this->cluster = 'default';
- }
- $this->nameSpaces = $mainConfig['params']['apolloYaml']['nameSpace'];
- //配置文件存储路径
- $configFile=dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'cache';
- //公共配置路径
- $publicConfigPath = dirname(__FILE__) .'/../config/';
- $apollo = new ApolloClient($this->server, $this->appId, $this->nameSpaces,$this->cluster,$configFile,$publicConfigPath);
- $apollo->start();
- }
- }
|