How to know whether solr server is running or not

不羁的心 提交于 2021-01-28 19:04:56

问题


I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

Below you can see an overview of my goal.

I'm using Magento CE 1.7.0.2 & Solr 4.6.0.

var url1 ="http://127.0.0.1:8080/solr/select?q=iphon&wt=json&json.wrf=?";
$.getJSON(url1,function(result){
   // my logic 
});

when the Solr Server is Running means this script is working fine.But if my Solr Server is Not Running means it'll not work.

But my goal is to write this script like this...

if( Solr Server is Running){
   var url1 ="http://127.0.0.1:8080/solr/select?q=iphon&wt=json&json.wrf=?";
   $.getJSON(url1,function(result){
      // my logic-1
   });
}else{
   // my logic-2
}

So how do i know that whether the Solr Server is running or Not ?

& i know this is the duplicate question but i never find solution so please ignore it.

Any Ideas ?


回答1:


Don't know how SOLR works, but proper jQuery would be:

$.ajax({
    type: "GET",
    url: "http://127.0.0.1:8080/solr/select?q=iphon&wt=json&json.wrf=?",
    dataType: "json",
    success: function (result) {
        // is working
    },
    error: function (result) {
        // probably not
    }
});



回答2:


Use setTimeout before trying to connect. If you are successful use clearTimeout. If you are not within the setTimeout-time you can do what you have defined setTimeout to do.




回答3:


You could just use the built in Solr Ping handler:

http://hostname:port/solr/admin/ping

This will give you the info you need.

Si




回答4:


<?php 
       $solr = new Apache_Solr_Service( 'HOST', 'PORT NUM', '/solr' );
       if ( $solr->ping() ) {
          // APACHE SOLR SERVER IS RUNNING 
       }else{
          // APACHE SOLR SERVER IS NOT RUNNING
       }
?>

I hope it will use full for some one.



来源:https://stackoverflow.com/questions/22293498/how-to-know-whether-solr-server-is-running-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!