'force', ]); } /** * 初始化 * @throws Exception */ public function init() { parent::init(); $this->prepareSettings(); } /** * 初始化配置信息 * @throws Exception */ protected function prepareSettings() { $runtimePath = \Yii::$app->getRuntimePath(); $this->settings = [ 'host' => '127.0.0.1', 'port' => '9515', 'process_name' => 'swooleRPCServer', 'open_tcp_nodelay' => '1', 'daemonize' => '1', 'worker_num' => '2', 'task_worker_num' => '2', 'task_max_request' => '10000', 'debug' => true, 'pidfile' => $runtimePath.'/tmp/yii2-swoole-rpc.pid', 'log_dir' => $runtimePath.'/yii2-swoole-rpc/log', 'task_tmpdir' => $runtimePath.'/yii2-swoole-rpc/task', 'log_file' => $runtimePath.'/yii2-swoole-rpc/log/rpc.log', 'log_size' => 204800000, 'ipWhiteList' => [], 'username' => '', 'password' => '', ]; try { $settings = \Yii::$app->params['swooleRPC']; }catch (\Exception $e) { throw new Exception('Empty param swooleRPC in params. ',8); } $this->settings = ArrayHelper::merge( $this->settings, $settings ); } /** * 启动服务 参数:start 启动,stop 停止,restart 重启,stats 查看状态,list 查看进程列表 * @param string $mode * @throws Exception */ public function actionRun($mode='start'){ $rpcService = new RPCService($this->settings,\Yii::$app, $this); switch ($mode) { case 'start': $rpcService->serviceStart(); break; case 'restart': $rpcService->serviceStop(!!$this->force, function() use ($rpcService){ $rpcService->serviceStart(); }); break; case 'stop': $rpcService->serviceStop(!!$this->force); break; case 'stats': $rpcService->serviceStats(); break; case 'list': $rpcService->serviceList(); break; default: exit('error:参数错误'); break; } } }