Exemplo n.º 1
0
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $host = $input->getOption('host');
     $port = $input->getOption('port');
     $output->writeln(vsprintf('<info>Server running on port %s:%s.</info>', [$host, $port]));
     $server = new Server($this->getContainer()->getParameter('kernel.root_dir'), $host, $port);
     $server->setEnv($this->getContainer()->getParameter('kernel.environment'))->setStandalone($input->getOption('standalone'))->setApc($input->getOption('apc'))->setCache($input->getOption('cache'))->build()->run();
     $output->writeln('<info>Server stopped.</info>');
 }
Exemplo n.º 2
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param array $childrenPid
  * @param $host
  * @param array $ports
  * @param $useSupervisor
  * @return int
  */
 private function _fork(InputInterface $input, OutputInterface $output, array &$childrenPid, $host, array $ports, $useSupervisor)
 {
     $return = 0;
     foreach ($ports as $port) {
         $pid = pcntl_fork();
         if ($pid > 0) {
             // Parent proccess
             $lock_file = sys_get_temp_dir() . '/react-' . $host . '-' . $port . '.pid';
             $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE ?: $output->writeln("PID file: {$lock_file}", OutputInterface::VERBOSITY_DEBUG);
             file_put_contents($lock_file, $pid);
             $childrenPid[$pid] = ['host' => $host, 'port' => $port];
         } elseif ($pid < 0) {
             $output->writeln('<error>Child process could not be started. Server is not running.</error>');
             $return = 10;
         } else {
             pcntl_signal(SIGTERM, function ($signo) use($output) {
                 $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE ?: $output->writeln("> Received signal {$signo} : my PID " . posix_getpid());
                 switch ($signo) {
                     case SIGTERM:
                         exit(0);
                 }
             });
             // Child process
             if (!$useSupervisor && posix_setsid() < 0) {
                 $output->writeln('<error>Unable to set the child process as session leader</error>');
             }
             $output->writeln(vsprintf('<info>Server running on port %s:%s.</info>', [$host, $port]));
             $server = new Server($this->getContainer()->getParameter('kernel.root_dir'), $host, $port);
             $server->setEnv($this->getContainer()->getParameter('kernel.environment'))->setStandalone($input->getOption('standalone'))->setApc($input->getOption('apc'))->setCache($input->getOption('cache'))->build()->run();
         }
     }
     return $return;
 }