My Blog

PHP PECL Solr 2.1.0 Released

1.17.2015 | Blog, PHP

I’m pleased to announce that The Official PHP Solr Extension 2.1.0 is out with exciting features.


The Solr extension allows you to communicate effectively with The Apache Solr Server in PHP.

The Solr extension is an extremely fast, light-weight, feature-rich library that allows PHP developers to communicate effectively with Solr Server instances.

There are built-in tools to add documents and make updates to The Solr Server.

It also contains tools that allows you to build advanced queries to the server when searching for documents.
Versions 1.x of The PECL Extesion supports Apache Solr Server 1.3-3.x

Versions 2.x of The PECL Extension supports Apache Solr Server 4+


– New Feature: SolrDisMaxQuery Builder (dismax/edismax) [Feature #67101]
– Support PHPS (PHP Serialized) Response Writer [Request #61329]
– SolrResponse::getArrayResponse [Feature #67660]
– SolrResponse::getResponse() returns SolrObject instead of array (with json response writer) [Bug #67579]
– Argument list parameter: Argument to value separator disappears [Bug #68179]
– Conflict Occurs When using SolrDisMax::addBoostQuery and setBoostQuery [Bug #68181]
– Doc Fix [Doc #67542]
– Internals: simple_list parameter type allow custom delimiter
– Internals: Allowed zero-length argument value
– Internals: Allowed zero-length argument-to-argument-value separator
– Security Fix


1. Install shared extension

You can install PHP’s Solr Extension using one of the following methods:

1.a Through PECL
pecl install solr
1.b Through YUM
yum install php-pecl-solr2
1.c Compile from the source
make && sudo make install

2. Loading the extension

Debian Family:

echo '' | sudo tee /etc/php5/conf.d/solr.ini

sudo php5enmod solr
1.d For Windows

Windows Shared Extensions are available on PECL as shared DLLs(solr.dll ) compiled on all of the PHP supported versions.

Usage Examples

For Full Examples download the package file and extract it, under the examples directory. You can download it through PECL’s Website.

I’ll post here just one example to illustrate the capabilities of the new SolrDisMaxQuery.

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

/* Domain name of the Solr server */
define('SOLR_SERVER_HOSTNAME', 'localhost');

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

/* SOLR CORE to test on */

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

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

$options = array
		'hostname' => SOLR_SERVER_HOSTNAME,
		'login'    => SOLR_SERVER_USERNAME,
		'password' => SOLR_SERVER_PASSWORD,
		'port'     => SOLR_SERVER_PORT,
		'path'     => SOLR_SERVER_PATH

$client = new SolrClient($options);

$disMaxQuery = new SolrDisMaxQuery();

// $disMaxQuery->addParam('debugQuery','true');


$disMaxQuery->addSortField('price', SolrQuery::ORDER_ASC);

->addBigramPhraseField('type', 3, 4)
->setTrigramPhraseFields('content^0.5 anchor~4^1.5 title^1.2 site^1.5')

$queryResponse = $client->query($disMaxQuery);

$response = $queryResponse->getResponse();

if($response->response->numFound > 0) {
	$docs = $response->response->docs;
} else {
	echo "No Documents Found".PHP_EOL;

Please visit Apache Solr Wiki for more information about the parameters and usage of the DisMax Query Parser.

PHP Class stubs can be found on the tar package under docs/ or you can download it from the repo. It helps a lot with PHP IDEs.

Documentation Reference: PHP Docs.

Be Sociable, Share!



Hi Omar,
first of all thank you very much for your work.
Is there any plan to have a version of pecl-solr compatible with PHP 7?



Omar Shaban

Hello Emanuele,

Yes, the version is in progress. ETA: by the end of December.

Thank you for using the extension.

Omar Shaban

2.4.0 released with php7 support, performance optimizations and bug fixes. Please check the changelog.


Great, looking forward to use it.




Hello Omar,

any news for PHP 7 support?


Omar Shaban

2.4.0 released with php7 support, performance optimizations and bug fixes. Please check the changelog. Thanks for using Solr Extension.