Using Solr with PHP

半世苍凉 提交于 2020-01-17 04:19:25

问题


I am trying to use solr with php . I have configured my solr application and it's working fine . However I am not able to communicate with solr using php . I have tried a number of extensions : pecl-solr , solr-php-client and Solarium . However none were able to even ping my solr server . All this while my solr server is available at localhost:8080/solr . I am running it on windows with tomcat . (I have checked my tomcat and solr services all the while when pinging through php , they were up and running )

I think I am doing something very basic wrong here . Does my solr application need to be in htdocs in xampp ? Because I have it inside the webapps folder of my tomcat server . I dont really see how it could make a difference since I specifically provided the path to ping in solr-php-client like this :

 require_once( 'Apache/Solr/service.php' );


 $solr = new Apache_Solr_Service( 'localhost', '8080', '/solr' );
  var_dump($solr) ; 
  if ( ! $solr->ping() ) {
     echo 'Solr service not responding.';
      exit;
    }

I get the 'Solr service not responding' message on running this code . Any suggestions ?

Update : I was looking under the hood and found that for getting the contents , the following php function is used : file_get_contents I further came to know that when the file is located through a URI it may fail as many servers block this command because of security concerns . Is this true for xampp as well ? Running on my local machine that is ?


回答1:


Try this i hope it'll helpful to you, & its working for me.

$solr = new Apache_Solr_Service( 'localhost', '8080', '/solr' );
  var_dump($solr) ; 
  if ( $solr->ping() ) {
     echo 'Solr Server Responding.';
      // your code
    }else{
      echo "Solr Server is not Running";
    }

from your code just remove require_once( 'Apache/Solr/service.php' ); this.




回答2:


You are not able to ping your solr server because of you not mentioned the your core name.

require_once('Apache/Solr/Service.php');
$solr = new Apache_Solr_Service( 'localhost', '8080', '/solr/CORE_NAME' 
 );
var_dump($solr) ;
if ( ! $solr->ping() ) {
 echo 'Solr service not responding.';
  exit;
}

You just have to add core name

$solr = new Apache_Solr_Service( 'localhost', '8080', '/solr/CORE_NAME');

Once you pass core name created by you it will started working for you.



来源:https://stackoverflow.com/questions/13900912/using-solr-with-php

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