You are here

public function DrupalApacheSolrService::ping in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::ping()
  2. 6.3 Drupal_Apache_Solr_Service.php \DrupalApacheSolrService::ping()

Call the /admin/ping servlet, to test the connection to the server.

Parameters

$timeout: maximum time to wait for ping in seconds, -1 for unlimited (default 2).

Return value

(float) seconds taken to ping the server, FALSE if timeout occurs.

Overrides DrupalApacheSolrServiceInterface::ping

1 call to DrupalApacheSolrService::ping()
DrupalApacheSolrService::clearCache in ./Drupal_Apache_Solr_Service.php
Clear cached Solr data.

File

./Drupal_Apache_Solr_Service.php, line 125

Class

DrupalApacheSolrService
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Code

public function ping($timeout = 2) {
  $start = microtime(TRUE);
  if ($timeout <= 0.0) {
    $timeout = -1;
  }
  $pingUrl = $this
    ->_constructUrl(self::PING_SERVLET);

  // Attempt a HEAD request to the solr ping url.
  $options = array(
    'method' => 'HEAD',
    'timeout' => $timeout,
  );
  $response = $this
    ->_makeHttpRequest($pingUrl, $options);
  if ($response->code == 200) {

    // Add 0.1 ms to the ping time so we never return 0.0.
    return microtime(TRUE) - $start + 0.0001;
  }
  else {
    return FALSE;
  }
}