Knp\Bundle\KnpBundlesBundle\Utils\SolrUtils::getSolrPid PHP Method

getSolrPid() public method

Get SOLR pid
public getSolrPid ( ) : integer
return integer
    public function getSolrPid()
    {
        $process = new Process(sprintf('ps aux | grep \\\\%s | grep -v grep | awk \'{ print $2 }\'', $this->buildProperties('| grep \\\\')));
        $process->run();
        $pid = $process->getOutput();
        return (int) $pid;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->utils = $this->getContainer()->get('knp_bundles.utils.solr');
     if ($input->getOption('show-commands-only')) {
         $output->writeln(sprintf('<info>%s</info>', $this->createRunSolrCommand($input)));
         return 0;
     }
     if ($this->utils->isSolrRunning()) {
         $output->writeln(sprintf('<info>%s %d</info>', 'Solr is running. Pid: ', $this->utils->getSolrPid()));
         return 0;
     }
     $output->writeln(sprintf('<info>%s</info>', 'Starting solr in background process'));
     $process = new Process($this->createRunSolrCommand($input));
     $process->run();
     $output->writeln(sprintf('<info>Pid: %d</info>', $this->utils->getSolrPid()));
     return 0;
 }