问题
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