Beispiel #1
0
 public function onServe()
 {
     require_once SERVER_BASE . 'thirdparty/MNLogger/MNLogger.php';
     $logdir = PHPServerConfig::get('monitor_log_path') ? PHPServerConfig::get('monitor_log_path') : '/home/logs/monitor';
     $config = array('on' => true, 'app' => 'php-rpc-server', 'logdir' => $logdir);
     try {
         self::$rpcMNLogger = @thirdparty\MNLogger\MNLogger::instance($config);
     } catch (Exception $e) {
     }
     // 初始化统计上报地址
     $report_address = PHPServerConfig::get('workers.' . $this->serviceName . '.report_address');
     if ($report_address) {
         StatisticClient::config(array('report_address' => $report_address));
     } else {
         if ($config = PHPServerConfig::get('workers.StatisticWorker')) {
             if (!isset($config['ip'])) {
                 $config['ip'] = '127.0.0.1';
             }
             StatisticClient::config(array('report_address' => 'udp://' . $config['ip'] . ':' . $config['port']));
         }
     }
     // 业务引导程序bootstrap初始化(没有则忽略)
     $bootstrap = PHPServerConfig::get('workers.' . $this->serviceName . '.bootstrap');
     if (is_file($bootstrap)) {
         require_once $bootstrap;
     }
     // 服务名
     self::$appName = $this->serviceName;
 }
Beispiel #2
0
 /**
  * 进程启动时的一些初始化
  * @see PHPServerWorker::onServe()
  */
 public function onServe()
 {
     // 初始化thrift生成文件存放目录
     $provider_dir = PHPServerConfig::get('workers.' . $this->serviceName . '.provider');
     if ($provider_dir) {
         if ($this->providerDir = realpath($provider_dir)) {
             if ($path_array = explode('/', $this->providerDir)) {
                 $this->providerNamespace = $path_array[count($path_array) - 1];
             }
         } else {
             $this->providerDir = $provider_dir;
             $this->notice('provider_dir ' . $provider_dir . ' not exsits');
         }
     }
     // 初始化thrift生成类业务实现存放目录
     $handler_dir = PHPServerConfig::get('workers.' . $this->serviceName . '.handler');
     if ($handler_dir) {
         if ($this->handlerDir = realpath($handler_dir)) {
             if ($path_array = explode('/', $this->handlerDir)) {
                 $this->handlerNamespace = $path_array[count($path_array) - 1];
             }
         } else {
             $this->handlerDir = $handler_dir;
             $this->notice('handler_dir' . $handler_dir . ' not exsits');
         }
     } else {
         $this->handlerDir = $provider_dir;
     }
     // 统一日志类初始化
     require_once SERVER_BASE . 'thirdparty/MNLogger/MNLogger.php';
     $logdir = PHPServerConfig::get('monitor_log_path') ? PHPServerConfig::get('monitor_log_path') : '/home/logs/monitor';
     $config = array('on' => true, 'app' => 'php-rpc-server', 'logdir' => $logdir);
     try {
         self::$rpcMNLogger = @thirdparty\MNLogger\MNLogger::instance($config);
     } catch (Exception $e) {
     }
     // 初始化统计上报地址
     $report_address = PHPServerConfig::get('workers.' . $this->serviceName . '.report_address');
     if ($report_address) {
         StatisticClient::config(array('report_address' => $report_address));
     } else {
         if ($config = PHPServerConfig::get('workers.StatisticWorker')) {
             if (!isset($config['ip'])) {
                 $config['ip'] = '127.0.0.1';
             }
             StatisticClient::config(array('report_address' => 'udp://' . $config['ip'] . ':' . $config['port']));
         }
     }
     // 业务引导程序bootstrap初始化(没有则忽略)
     $bootstrap = PHPServerConfig::get('workers.' . $this->serviceName . '.bootstrap');
     if (is_file($bootstrap)) {
         require_once $bootstrap;
     }
     // 服务名
     self::$appName = $this->serviceName;
 }