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

isSolrRunning() public method

public isSolrRunning ( ) : boolean
return boolean
    public function isSolrRunning()
    {
        // create a ping query
        $ping = $this->solarium->createPing();
        // execute the ping query
        try {
            $result = $this->solarium->ping($ping);
            $result = $result->getData();
            return isset($result['status']) && 'OK' == $result['status'];
        } catch (\Solarium_Exception $e) {
            return false;
        }
    }

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;
 }