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. A quick look at 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. When I run solr_test.php, I get the following error:

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. Is that correct?

Do I need to set up an additional Virtual Host for Solr, e.g solr.mysite?

Here is my bootstrap.php file:


/* 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:


include "bootstrap.php";

$options = array
'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);




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. That said I feel like your PHP script should error out. See if something like

define('SOLR_SERVER_PORT', 8983);

remedies the situation.

Make sure Solr server details are correct. I get this error only when I pass something wrong like SOLR_SERVER_PORT etc.

Please try following terminal commands may helps, to disable temporary firewall settings:

setenforce Permissive

Need Your Help

Lines of code you have written

perforce lines-of-code

Out of curiosity, is there any way to get the number of lines of code you have written (in a specific project)?

Extra zeros in OpenCV Mat

c++ opencv

Tried building 'cv::Mat' from 2D array but I find that extra zeros are added to the Mat which I am not able to understand. The code I tried is :