You are here

public function SolrConnectorPluginBase::pingCore in Search API Solr 8.3

Same name and namespace in other branches
  1. 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::pingCore()
  2. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::pingCore()
  3. 4.x src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::pingCore()

Pings the Solr core to tell whether it can be accessed.

Parameters

array $options: (optional) An array of options.

Return value

mixed The latency in milliseconds if the core can be accessed, otherwise FALSE.

Overrides SolrConnectorInterface::pingCore

2 calls to SolrConnectorPluginBase::pingCore()
StandardSolrCloudConnector::pingCollection in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Pings the Solr collection to tell whether it can be accessed.
StandardSolrCloudConnector::pingCore in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Pings the Solr core to tell whether it can be accessed.
1 method overrides SolrConnectorPluginBase::pingCore()
StandardSolrCloudConnector::pingCore in src/Plugin/SolrConnector/StandardSolrCloudConnector.php
Pings the Solr core to tell whether it can be accessed.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 533

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function pingCore(array $options = []) {
  $this
    ->connect();
  $this
    ->useTimeout();
  $query = $this->solr
    ->createPing();
  try {
    $start = microtime(TRUE);
    $result = $this->solr
      ->execute($query);
    if ($result
      ->getResponse()
      ->getStatusCode() == 200) {

      // Add 1 µs to the ping time so we never return 0.
      return microtime(TRUE) - $start + 1.0E-6;
    }
  } catch (HttpException $e) {

    // Don't handle the exception. Just return FALSE below.
  }
  return FALSE;
}