You are here

protected function SolrConnectorPluginBase::doPing in Search API Solr 8.2

Same name and namespace in other branches
  1. 8 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::doPing()

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

Parameters

string $endpoint_name: The endpoint to be pinged on the Solr server.

Return value

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

2 calls to SolrConnectorPluginBase::doPing()
SolrConnectorPluginBase::pingCore in src/SolrConnector/SolrConnectorPluginBase.php
Pings the Solr core to tell whether it can be accessed.
SolrConnectorPluginBase::pingServer in src/SolrConnector/SolrConnectorPluginBase.php
Pings the Solr server to tell whether it can be accessed.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 513

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

protected function doPing($options = [], $endpoint_name = 'core') {
  $this
    ->connect();

  // Default is ['handler' => 'admin/ping'].
  $query = $this->solr
    ->createPing($options);
  try {
    $start = microtime(TRUE);
    $result = $this->solr
      ->execute($query, $endpoint_name);
    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;
}