Latest happenings from my blog

View All Posts In My Blog »

PHP PECL Solr 2.1.0 Released


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 'extension=solr.so' | 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.

ZF Autocomplete: Zend Framework command autocompletion


zend framework

Zftool is a nifty feature from Zend Framework, however It’s pretty tiring to remember all commands.

Using bash I’ve got a bunch of custom providers, and for that I have to remember all the commands or review them every time, so It’s missing a killer feature which is the bash command autocompletion.


  1. Clone it.
  2. Move it to bash completion scripts directory to be able to autocomplete zf providers and zf provider actions
  3. Enable ItI you want to run it immediately in the same opened shell you can do the following command

Note: It will be automatically available in any new shell.

Custom Providers and Caching

In case you are wondering, I’ve got many projects with many custom providers, will it autocomplete them?

The answer is YES, and it fetches the providers per directory basis. Since the fetching and filtering is a pretty heavy process, it caches the autocompleted options in /tmp/ so that it will only be slow the first time, and then it’s going to be blazing fast.

Clear ZF autocomplete cache for providers and actions

To clear the cache, you will need to delete the cache files in tmp, the following command will do the job for you.

Hope that would be helpful for you!

CakePHP Locale and Routing

1 Comment


When I was working on the cakephp localization ( l10n ) and internationalization ( i18n ), I came across a problem so I decided to let the world know about it if anyone had got the same issue.

What we want here is that a user can go to the localized version of the website according to the URL identified, for instance we want the website to load the English locale when we pass a URL like this http://example.tld/eng/Controller/Action

The problem is that while implementing the routes for the language detection, the plugins made a conflict with the rules in the routes file. Language routing is easy but sometimes can be tricky.
Read more…