How to add docs to Solr using PHP? - php

I've got Solr set up on my server, and a test collection loaded.
Without installing anything else, I can search the collection fine using the Solr URL and JSON decoding file_get_contents($url).
In order to add/update/delete documents, do I need to install a PHP Solr client? Or is there a native way that is standard to use? If the former, is this the one to install?: http://www.php.net/manual/en/book.solr.php - or can you recommend another and why?

Check the below links :
Integrate SOLR - wiki
SOLR PHP - Official Client Library
Link to download SOLR php client library

In my company we've been successfully using the native Solr client for PHP that you've mentioned for a while now. I also found Solarium helpful, however it has it's limitations, so it might be worth looking into using HTTP request tools like Guzzle, Httpful and such.

Related

how can an extension interact with a DB without forcing the users to install a server and php

I am writing a Chrome extension which sends some data to a PHP file, which then the PHP file sends it to a database.
All is fine and well, but I just wanted to ask if my users need to have PHP as well as a server installed on their machines, for the extension to work?
According to some posts it does (for example). But if this indeed the case, then how can an extension interact with a database without forcing the users to install a server and PHP.
Thanks in advance.
php is a server side scripting language, meaning that all of the processing is done on your server. there is no reason that any user would need to install anything in able to access a php application.
You might want to look into WebSQL (http://en.wikipedia.org/wiki/Web_SQL_Database).
It's not developed anymore (and stays unfinished), but according to this Wikipedia article it's based on SQLite and chrome supports is.
You can interact with a database (IndexedDB) using JS in your extension.
Resources:
Can I use...
IndexedDB | MDN
Since you are making a Chrome extension, there may not be any concern for cross-browser support, but according to HTML5 Please, a polyfill is recommended.

What's the common practice to invoke a JSON call in PHP?

I'm trying to make a JSON call library. It has the following features.
be able to customize the header
be able to POST any data to server(including form-encoding (a=1&b=2&c=3) and JSON data chunk)
parse the response and return as a JSON object
I searched in other questions and found that there are only two answers.
use file_get_contents(). This way is pretty simple and easy to use; however, you cannot do anything more than get the content -- you cannot add headers, cannot use POST. But it is usually supported by all servers.
use curl. This way seems powerful and you can do nearly everything with it. The disadvantage is that you have to install libcurl and php-curl support on your server, which means you may not use it on servers that have no curl installed.
So, if I want to develop a common library that can be used on most server, is curl a good choice?
Is there any other ways to do this?
In a short word, I'm looking for a PHP version of urllib2 in python - easy to use, powerful, and reliable.
You have two options: curl and HTTP stream context options. Both can accomplish what you have described; curl might not be installed everywhere, while stream contexts are a core feature and are always available.
Actually, you can also implement your library using sockets, which would be more work but will probably allow you greater control if you need to do weirder things with your requests.
As i know, curl is included in mostly on many server, since it supported from 4.0.2 PHP version natively.
Also there is a native php function header, which customizes your response's headers by simply using like this -> header('location: index.php'), header('cache-control: ok') and so on. You can view Network Functions section on php.net

PHP, Bitmaps, and Redis

I found this blog post and would like to experiment with it more.. The issue is my environment is PHP and not Java. I've looked for how I can translate the code examples I would like to use into PHP but it doesn't look like there is much documentation on PHP and Bitmaps. Any help would be awesome!
Thanks!
http://blog.getspool.com/2011/11/29/fast-easy-realtime-metrics-using-redis-bitmaps/
Actually, you do not really need to handle the bitmaps in the PHP code, provided you use a recent Redis version (2.6), and a compliant PHP client library.
See the following Redis commands:
http://redis.io/commands/bitop
http://redis.io/commands/bitcount
So you can count the bits directly in Redis rather than doing it in PHP.

SOAP MTOM/XOP Support in PHP

I want to create a Web Service in PHP, which can support MTOM/XOP. My Webservice Processing function shpuld be able to extract the attachment. As I googled I could find only WSF(Web Service Framework) as an answer.
Is there any alternatives? I'm new to this MTOM/XOP thing. Currently I use NuSoap but it dont support MTOM/XOP.
There is a patch to support mtom, it might need tweaking for the full mtom spec
http://sourceforge.net/projects/nusoap/forums/forum/193578/topic/3917337

Generate SNMP traps with PHP

I'm desperately searching for a way to generate SNMP traps from PHP. I know the build in methods to use snmpget but I was not able to figure out how to send SNMP traps.
Does anybody know a class / code snippet for it? Searching the web did not bring up anything other than using exec to call cli tools which is definately no option for me.
I suspect that it would be neccessary to use socket_create and corresponding functionality to generate the UDP package manually...
As far as I know, there is no native way for generating traps/informs with php. Even the SNMP extension only permits get and set requests. So the only (quick) way to accomplish this is to call an external tool like net-snmp. The proper command line would be something like
snmptrap -v 1 -c public manager enterprises.spider test-hub 3 0 '' interfaces.iftable.ifentry.ifindex.1 i 1
will send a generic linkUp trap to manager, for interface 1 (taken from the manpage). To execute this from php the net-snmp binaries should be on the path of the system and you could either call exec, shell_exec or proc_open.
Obvisouly you also can send the trap by yourself by encoding it as raw byte array and sending it over an UDP socket, but then you had to implement a BER encoder and a SNMP packet encoder all by yourself which I don't recommend. For your reference, you would need those informations:
Basic Encoding Rules
ASN.1
and some further links found
here
There are no core SNMP trap libraries. Or even any core libraries that will help you package an SNMP udp packet. I did however find this abandoned project. http://code.google.com/p/php-snmp/ which provides most of what you would need to send a simple trap.
A little more active but a lot more complex seems to be http://www.activexperts.com/network-component/howto/snmpts/php/
For anybody searching for such a library these days (in 2019), I found https://github.com/FreeDSx/SNMP which supports sending SNMPv1 and SNMPv2 traps (including inform requests).
I know this question is old, but I just came across it via Google, and thought to update it according to my findings in case someone else also lands here.
As Jek answered, using net-snmp is the best solution.
Although the original post said that he didn't want to use any external components, consider you can now add net-snmp though apt-get (look up package php-snmp) for many Linux distro's, and I'm sure installing on Windows will be equally easy.
The great benefit of using it, is as of PHP 5.3.3, PHP inherintly has built-in interface functions to use SNMP, so that you don't have to use exec, shell_exec or proc_open. Everything can be done in a PHP environment.
See http://php.net/manual/en/book.snmp.php

Categories