You are here

public function SolrConnectorPluginBase::pingEndpoint in Search API Solr 4.x

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

Parameters

\Solarium\Core\Client\Endpoint|null $endpoint:

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

Return value

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

Overrides SolrConnectorInterface::pingEndpoint

1 call to SolrConnectorPluginBase::pingEndpoint()
SolrConnectorPluginBase::pingCore in src/SolrConnector/SolrConnectorPluginBase.php
Pings the Solr core to tell whether it can be accessed.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 611

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

public function pingEndpoint(?Endpoint $endpoint = NULL, array $options = []) {
  $this
    ->connect();
  $this
    ->useTimeout(self::QUERY_TIMEOUT, $endpoint);
  $query = $this->solr
    ->createPing($options);
  try {
    $start = microtime(TRUE);
    $result = $this->solr
      ->execute($query, $endpoint);
    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;
}