예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function run($tasks, $servers, $environments, $input, $output)
 {
     $this->tasks = $tasks;
     $this->servers = $servers;
     $this->input = $input;
     $this->output = new OutputWatcher($output);
     $this->informer = new Informer($this->output);
     $this->port = self::START_PORT;
     connect:
     $this->pure = new Server($this->port);
     $this->loop = $this->pure->getLoop();
     // Start workers for each server.
     $this->loop->addTimer(0, [$this, 'startWorkers']);
     // Wait for output
     $this->outputStorage = $this->pure['output'] = new QueueStorage();
     $this->loop->addPeriodicTimer(0, [$this, 'catchOutput']);
     // Lookup for exception
     $this->exceptionStorage = $this->pure['exception'] = new QueueStorage();
     $this->loop->addPeriodicTimer(0, [$this, 'catchExceptions']);
     // Send workers tasks to do.
     $this->loop->addPeriodicTimer(0, [$this, 'sendTasks']);
     // Wait all workers finish they tasks.
     $this->loop->addPeriodicTimer(0, [$this, 'idle']);
     // Start loop
     try {
         $this->pure->run();
     } catch (ConnectionException $exception) {
         // If port is already used, try with another one.
         $output->writeln("<error>" . $exception->getMessage() . "</error>");
         if (++$this->port <= self::STOP_PORT) {
             goto connect;
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
         $output->writeln('<info>PurePHP server started.</info>');
     }
     $server = new Server($input->getOption('port'), $input->getOption('host'));
     if (OutputInterface::VERBOSITY_DEBUG <= $output->getVerbosity()) {
         $server->setLogger(function ($log) use($output) {
             $output->writeln($log);
         });
     }
     $server->run();
 }