You are here

function apachesolr_server_status in Apache Solr Search 7

Same name and namespace in other branches
  1. 8 apachesolr.module \apachesolr_server_status()
  2. 6.3 apachesolr.module \apachesolr_server_status()
  3. 6.2 apachesolr.module \apachesolr_server_status()

Checks if a specific Apache Solr server is available.

Return value

boolean TRUE if the server can be pinged, FALSE otherwise.

5 calls to apachesolr_server_status()
AbstractDrupalSolrOnlineWebTestCase::setUpSolr in tests/solr_index_and_search.test
apachesolr_environment_edit_test_submit in ./apachesolr.admin.inc
Submit handler for the test button in the environment edit page
apachesolr_settings in ./apachesolr.admin.inc
Form builder for general settings used as a menu callback.
apachesolr_status_page in ./apachesolr.admin.inc
Gets information about the fields already in solr index.
DrupalSolrOfflineEnvironmentWebTestCase::testServerOffline in tests/apachesolr_base.test
Asserts that the module was installed and that a notice appears that the server is offline

File

./apachesolr.module, line 1477
Integration with the Apache Solr search application.

Code

function apachesolr_server_status($url, $class = NULL) {
  $status =& drupal_static(__FUNCTION__, array());
  if (!interface_exists('DrupalApacheSolrServiceInterface')) {
    require_once dirname(__FILE__) . '/apachesolr.interface.inc';
  }
  if (empty($class)) {
    $class = variable_get('apachesolr_service_class', 'DrupalApacheSolrService');
  }
  $key = $url . '|' . $class;

  // Static store insures we don't ping the server more than once per page load.
  if (!isset($status[$key])) {
    $ping = FALSE;
    try {

      // Takes advantage of auto-loading.
      // @Todo : Do we have to specify the env_id?
      $solr = new $class($url);
      $ping = @$solr
        ->ping(variable_get('apachesolr_ping_timeout', 4));
    } catch (Exception $e) {
      apachesolr_log_exception($url, $e);
    }
    $status[$key] = $ping;
  }
  return $status[$key];
}