views:

282

answers:

4

I am using PHP to access Solr and I wonder one thing.

Why should I use Solr PHP client when I can use:

$serializedResult = file_get_contents(
                      'http://localhost:8983/solr/select?q=niklas&wt=phps');

to get the result in arrays and then print them out? I don't really get the difference. Are there any richer features with the PHP client?

+2  A: 

I think because of following reasons:

  • Flexibility
  • Error Handling
  • Security Issues
  • Extendibility

All issues are the headache of these pre-made scripts and frameworks. So if there is a solution for certain thing, i would recommend you to go with that rather than doing everything from your own.

Also since these scripts and frameworks have good community support, there are lesser bugs, security issues and more.

Sarfraz
but what would the problem be when just using file_get_contents? it sends and i reveice? it works on every browser etc. just dont get what security/flexibility issues this could give..
weng
To reiterate Sarfraz's comment, you can do file_get_contents. But you still need to do your parsing, and if you use a client library you get the 4 things he specified!
Eric Pugh
A: 

I guess that the solr client just parses the results and provides you convenient way to pass the parameters (constructing the URL for you etc.).

Michal Čihař
A: 

To use, file_get_contents()... your php must have "allow_url_open" enabled. If you host your website on certain hosts then they dont allow to use this function because of they keep this setting OFF.

letsnurture
A: 

In some cases, however, it might make sense to do file_get_contents(). SolrClient doesn't have anything for field collapsing (it's a patch not available in the trunk) so I have to either write my own class which mimics SolrClient and SolrQuery if I can't do it with the PECL library.

Moazzam Khan