简体   繁体   English

PHP中的Apache Solr扩展-Solr HTTP错误:“无法连接到服务器”

[英]Apache Solr extension in PHP - Solr HTTP Error : 'Couldn't connect to server'

I am trying to install the Apache Solr extension for PHP on my Windows box. 我正在尝试在Windows框中安装PHP的Apache Solr扩展。 A quick look at phpinfo(); 快速浏览phpinfo(); shows that the extension has been loaded. 显示扩展已加载。 在此处输入图片说明

Apart from changing SOLR_SERVER_HOSTNAME to match my own Virtual Host, everything as the same as on the PHP Solr Example page . 除了更改SOLR_SERVER_HOSTNAME以匹配我自己的虚拟主机之外,其他所有操作都与“ PHP Solr示例”页面上的相同。 When I run solr_test.php, I get the following error: 当我运行solr_test.php时,出现以下错误:

Warning: SolrClient::addDocument(): Solr HTTP Error : 'Couldn't connect to server'

The PHP Solr page says: The Solr extension allows you to communicate effectively with the Apache Solr server in PHP 5 so I am assuming that I do not need to run anything else to make this extension work. PHP Solr页面上说:Solr扩展允许您与PHP 5中的Apache Solr服务器进行有效的通信,因此我假设不需要运行其他任何东西即可使此扩展正常工作。 Is that correct? 那是对的吗?

Do I need to set up an additional Virtual Host for Solr, eg solr.mysite? 我是否需要为Solr设置其他虚拟主机,例如solr.mysite?

Here is my bootstrap.php file: 这是我的bootstrap.php文件:

<?php

/* Domain name of the Solr server */
define('SOLR_SERVER_HOSTNAME', 'test.mysite');

/* Whether or not to run in secure mode */
define('SOLR_SECURE', true);

/* HTTP Port to connection */
define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8443 : 8983));

/* HTTP Basic Authentication Username */
define('SOLR_SERVER_USERNAME', 'admin');

/* HTTP Basic Authentication password */
define('SOLR_SERVER_PASSWORD', 'changeit');

/* HTTP connection timeout */
/* This is maximum time in seconds allowed for the http data transfer operation.     Default value is 30 seconds */
define('SOLR_SERVER_TIMEOUT', 10);

?>

Here is my solr_test.php page: 这是我的solr_test.php页面:

<?php

include "bootstrap.php";

$options = array
(
'hostname' => SOLR_SERVER_HOSTNAME,
'login'    => SOLR_SERVER_USERNAME,
'password' => SOLR_SERVER_PASSWORD,
'port'     => SOLR_SERVER_PORT,
);

$client = new SolrClient($options);

$doc = new SolrInputDocument();

$doc->addField('id', 334455);
$doc->addField('cat', 'Software');
$doc->addField('cat', 'Lucene');

$updateResponse = $client->addDocument($doc);

print_r($updateResponse->getResponse());

?>

I'm a bit concerned about this line here: 我在这里有点担心:

 
 
 
  
  define('SOLR_SERVER_PORT', ((SOLR_SECURE) ? 8443 : 8983));
 
  

As far as I'm aware this type of logic will only be supported in PHP 5.6. 据我所知,这种逻辑仅在PHP 5.6中受支持。 That said I feel like your PHP script should error out. 就是说,我觉得您的PHP脚本应该出错。 See if something like 看是否有类似的东西

 
 
 
  
  define('SOLR_SERVER_PORT', 8983);
 
  

remedies the situation. 纠正这种情况。

Make sure Solr server details are correct. 确保Solr服务器详细信息正确。 I get this error only when I pass something wrong like SOLR_SERVER_PORT etc. 仅当我传递SOLR_SERVER_PORT等错误信息时,我才收到此错误。

Please try following terminal commands may helps, to disable temporary firewall settings: 请尝试使用以下终端命令可能会有所帮助,以禁用临时防火墙设置:

sestatus
setenforce Permissive

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM