Beispiel #1
0
 public function run()
 {
     $option = ['name' => $this->name, 'worker' => 'EPS\\Bootstrap\\MultiProcessWorker\\Main', 'param' => ['dispatcherOption' => $this->dispatcherOption, 'serverOption' => $this->serverOption, 'logicOption' => $this->logicOption]];
     if ($this->daemon) {
         ChildProcess::instance($option)->daemon(true);
     } else {
         ChildProcess::instance($option)->run(true);
     }
     // return $this;
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
 public function __construct()
 {
     $this->param = ChildProcess::current()->getWorkerParam();
 }