You are here

public function Drupal_Apache_Solr_Service::ping in Apache Solr Search 6.2

Same name and namespace in other branches
  1. 5.2 Drupal_Apache_Solr_Service.php \Drupal_Apache_Solr_Service::ping()
  2. 6 Drupal_Apache_Solr_Service.php \Drupal_Apache_Solr_Service::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.

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

File

./Drupal_Apache_Solr_Service.php, line 41

Class

Drupal_Apache_Solr_Service

Code

public function ping($timeout = 2) {
  $start = microtime(TRUE);
  if ($timeout <= 0.0) {
    $timeout = -1;
  }

  // Attempt a HEAD request to the solr ping url.
  list($data, $headers) = $this
    ->_makeHttpRequest($this->_pingUrl, 'HEAD', array(), NULL, $timeout);
  $response = new Apache_Solr_Response($data, $headers);
  if ($response
    ->getHttpStatus() == 200) {

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