ApolloConfigMonitorCommand.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * 监控配置中心
  4. */
  5. require_once(dirname(__FILE__) .'/../extensions/apollo/ApolloClient.php');
  6. class ApolloConfigMonitorCommand extends CConsoleCommand {
  7. public $server; //指定apollo的服务地址
  8. public $appId;
  9. public $cluster; //配置中心集群,对应本地环境
  10. public $nameSpaces=array(); //指定要拉取哪些namespace的配置
  11. public function init() {
  12. parent::init();
  13. @ini_set('memory_limit', '1024M');
  14. set_time_limit(0);
  15. }
  16. public function actionIndex($YII_ENV='development'){
  17. //读取apollo配置
  18. $mainConfig=require dirname(__FILE__) .'/../config/main.'. $YII_ENV .'.php';
  19. $this->server=$mainConfig['params']['apollo']['server'];
  20. $this->appId=$mainConfig['params']['apollo']['appId'];
  21. $this->cluster=$YII_ENV; //配置中心集群,对应本地环境
  22. //集群
  23. if ($YII_ENV == 'development') {
  24. $this->cluster = 'dev';
  25. }
  26. //集群
  27. if ($YII_ENV == 'production') {
  28. $this->cluster = 'default';
  29. }
  30. $this->nameSpaces = $mainConfig['params']['apollo']['nameSpace'];
  31. //配置文件存储路径
  32. $configFile=dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'cache';
  33. //公共配置路径
  34. $publicConfigPath = dirname(__FILE__) .'/../config/';
  35. $apollo = new ApolloClient($this->server, $this->appId, $this->nameSpaces,$this->cluster,$configFile,$publicConfigPath);
  36. $apollo->start();
  37. }
  38. //读取Yaml格式配置
  39. public function actionTask($YII_ENV='development'){
  40. //读取apollo配置
  41. $mainConfig=require dirname(__FILE__) .'/../config/main.'. $YII_ENV .'.php';
  42. $this->server=$mainConfig['params']['apolloYaml']['server'];
  43. $this->appId=$mainConfig['params']['apolloYaml']['appId'];
  44. $this->cluster=$YII_ENV; //配置中心集群,对应本地环境
  45. //集群
  46. if ($YII_ENV == 'production') {
  47. $this->cluster = 'default';
  48. }
  49. $this->nameSpaces = $mainConfig['params']['apolloYaml']['nameSpace'];
  50. //配置文件存储路径
  51. $configFile=dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'cache';
  52. //公共配置路径
  53. $publicConfigPath = dirname(__FILE__) .'/../config/';
  54. $apollo = new ApolloClient($this->server, $this->appId, $this->nameSpaces,$this->cluster,$configFile,$publicConfigPath);
  55. $apollo->start();
  56. }
  57. }