public function __construct() { $this->param = ChildProcess::current()->getWorkerParam(); $this->dispatcher = $this->param['dispatcher']; $this->logic = new $this->param['dispatchLogic']($this->dispatcher); if (!$this->logic instanceof DispatchLogicInterface) { throw new \RuntimeException(sprintf('%s must instanceof EPS\\ServerDispatcher\\DispatcherInterface', $this->param['dispatchLogic']), 1); } $this->accept = $this->param['acceptMessage']; $this->receive = $this->param['receiveMessage']; //添加连接处理状态 EventLoop::addUsTimer([$this, 'onAccept'], 100); EventLoop::addUsTimer([$this, 'onReceive'], 10); }
public function start() { //启动Server $dispatcherOption = $this->param['dispatcherOption']; $accept = $dispatcherOption['acceptMessage']; $send = $dispatcherOption['sendMessage']; $receive = $dispatcherOption['receiveMessage']; $acceptMessage = Message::instance($accept['driver'], $accept['message'], $accept['option']); $receiveMessage = Message::instance($receive['driver'], $receive['message'], $receive['option']); $sendMessage = Message::instance($send['driver'], $send['message'], $send['option']); $dispatcher = $dispatcherOption['dispatcher']; $dispatcher = new $dispatcher($acceptMessage, $receiveMessage, $sendMessage); //启动Server进程 $option = ['name' => ChildProcess::current()->getName(), 'worker' => 'EPS\\Bootstrap\\MultiProcessWorker\\LogicWorker', 'param' => ['acceptMessage' => $acceptMessage, 'receiveMessage' => $receiveMessage, 'sendMessage' => $sendMessage, 'dispatcher' => $dispatcher, 'dispatchLogic' => $this->param['logicOption']['dispatchLogic']]]; $workerNums = isset($this->param['logicOption']['workerNum']) ? $this->param['logicOption']['workerNum'] : 1; for ($i = 0; $i < $workerNums; $i++) { ChildProcess::instance($option)->run(false); } //启动Server进程 $option = ['name' => ChildProcess::current()->getName(), 'worker' => 'EPS\\Bootstrap\\MultiProcessWorker\\Server', 'param' => ['acceptMessage' => $acceptMessage, 'receiveMessage' => $receiveMessage, 'sendMessage' => $sendMessage, 'dispatcherOption' => $dispatcherOption, 'serverOption' => $this->param['serverOption'], 'dispatcher' => $dispatcher]]; ChildProcess::instance($option)->run(false); }
public function __construct() { $this->param = ChildProcess::current()->getWorkerParam(); }