PHPPM\ProcessManager::run PHP Method

run() public method

Starts the main loop. Blocks.
public run ( )
    public function run()
    {
        Debug::enable();
        //make whatever is necessary to disable all stuff that could buffer output
        ini_set('zlib.output_compression', 0);
        ini_set('output_buffering', 0);
        ini_set('implicit_flush', 1);
        ob_implicit_flush(1);
        $this->loop = \React\EventLoop\Factory::create();
        $this->controller = new React\Server($this->loop);
        $this->controller->on('connection', array($this, 'onSlaveConnection'));
        $this->controllerHost = $this->getNewControllerHost();
        $this->controller->listen(5500, $this->controllerHost);
        $this->web = new \React\Socket\Server($this->loop);
        $this->web->on('connection', array($this, 'onWeb'));
        $this->web->listen($this->port, $this->host);
        $this->tcpConnector = new \React\SocketClient\TcpConnector($this->loop);
        $pcntl = new \MKraemer\ReactPCNTL\PCNTL($this->loop);
        $pcntl->on(SIGTERM, [$this, 'shutdown']);
        $pcntl->on(SIGINT, [$this, 'shutdown']);
        $pcntl->on(SIGCHLD, [$this, 'handleSigchld']);
        $pcntl->on(SIGUSR1, [$this, 'restartWorker']);
        if ($this->isDebug()) {
            $this->loop->addPeriodicTimer(0.5, function () {
                $this->checkChangedFiles();
            });
        }
        $this->isRunning = true;
        $loopClass = (new \ReflectionClass($this->loop))->getShortName();
        $this->output->writeln("<info>Starting PHP-PM with {$this->slaveCount} workers, using {$loopClass} ...</info>");
        for ($i = 0; $i < $this->slaveCount; $i++) {
            $this->newInstance(5501 + $i);
        }
        $this->loop->run();
    }

Usage Example

示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($workingDir = $input->getArgument('working-directory')) {
         chdir($workingDir);
     }
     $config = $this->loadConfig($input);
     if (file_exists($this->file)) {
         $modified = '';
         $fileConfig = json_decode(file_get_contents($this->file), true);
         if (json_encode($fileConfig) !== json_encode($config)) {
             $modified = ', modified by command arguments';
         }
         $output->writeln(sprintf('<info>Read configuration %s%s.</info>', realpath($this->file), $modified));
     }
     $output->writeln(sprintf('<info>%s</info>', getcwd()));
     $this->renderConfig($output, $config);
     $handler = new ProcessManager($output, $config['port'], $config['host'], $config['workers']);
     $handler->setBridge($config['bridge']);
     $handler->setAppEnv($config['app-env']);
     $handler->setDebug((bool) $config['debug']);
     $handler->setLogging((bool) $config['logging']);
     $handler->setAppBootstrap($config['bootstrap']);
     $handler->setMaxRequests($config['max-requests']);
     $handler->setPhpCgiExecutable($config['php-cgi']);
     $handler->setConcurrentRequestsPerWorker($config['concurrent-requests']);
     $handler->run();
 }
All Usage Examples Of PHPPM\ProcessManager::run