How to check if search_index's solr is running? To prevent fatal errors, I need to check if solr is running.

Given:

$solrIndex = \Drupal::entityTypeManager()
  -&gt;getStorage('search_api_index')
  -&gt;load('global');


How do I check if the solr server that $solrIndex is pointing to is online?

There is an ->isAvailable() method on the server object when you call the $index's ->getServerInstance() method, but it returns a false positive when the solr server is stopped:

I'm surprised I can't check it from the server object, but this returns a false positive when solr is stopped:

$false_positive = $solrIndex-&gt;getServerInstance()-&gt;isAvailable();
The SolrConnector plugin provides a pingServer() function that will determine it the endpoint can be accessed, so to really test it you likely need to be able to call that.

I'd first check to see if there is an abled server by calling $solrIndex-&gt;isServerEnabled(). 

Then I'd get the server, its backend, the connector, and run the ping:

$server = $solrIndex-&gt;getServerInstance();
$backend = $server-&gt;getBackend();
$connector = $backend-&gt;getSolrConnector();
$response = $connector-&gt;pingServer();


or just 

if( $solrIndex-&gt;getServerInstance()-&gt;getBackend()-&gt;getSolrConnector()-&gt;pingServer() ){ 
  // Yup
} 
else {
 // nope
}


The return value from pingServer() is:


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