/**
  * {@inheritdoc}
  */
 public function start(ServerContextInterface $context, RequestHandlerInterface $requestHandler)
 {
     $this->loop = Factory::create();
     $this->socketServer = new SocketServer($this->loop);
     $this->httpServer = new HttpServer($this->socketServer);
     $this->httpServer->on('request', $this->createRequestHandler($requestHandler));
     $this->socketServer->listen($context->getListenPort(), $context->getListenAddress());
     $this->loop->run();
 }
 /**
  * {@inheritdoc}
  */
 public function start(ServerContextInterface $context, RequestHandlerInterface $requestHandler)
 {
     $this->server = new \swoole_http_server($context->getListenAddress(), $context->getListenPort(), \SWOOLE_BASE);
     if (null !== $this->serverOptions) {
         $this->server->set($this->serverOptions->getOptions());
     }
     $this->server->on('request', $this->createRequestHandler($requestHandler));
     $this->server->start();
 }
 /**
  * @dataProvider provideExecuteWithContext
  *
  * @param string                 $address
  * @param int                    $port
  * @param ServerContextInterface $context
  */
 public function testExecuteWithContext($address, $port, ServerContextInterface $context = null)
 {
     $server = new ServerStub(function (ServerContextInterface $context) use($address, $port) {
         $this->assertSame($address, $context->getListenAddress());
         $this->assertSame($port, $context->getListenPort());
     });
     $requestHandler = $this->getMock(RequestHandlerInterface::class);
     /* @var RequestHandlerInterface $requestHandler */
     $exceptionHandler = $this->getMock(ExceptionHandlerInterface::class);
     /* @var ExceptionHandlerInterface $exceptionHandler */
     $executor = new Executor($server, $requestHandler, $exceptionHandler);
     $executor->execute($context);
 }
Beispiel #4
0
 /**
  * @param ServerContextInterface $context
  */
 private function logServerStart(ServerContextInterface $context)
 {
     $this->getLogger()->info(sprintf('The server(%s:%s) started(pid:%s)!', $context->getListenAddress(), $context->getListenPort(), posix_getpid()), array('serverClass' => get_class($this->server), 'requestHandlerClass' => get_class($this->requestHandler)));
 }