XMLRPC - Python Server, PHP Client. No consistancy? - php

I'm currently trying to build a web-base management interface for a cluster of linux servers running a special service. The idea being that the management website can RPC the clusters to gather information, perform configuration tasks, etc.
I've got an XMLRPC Python Server script up and running, and I've written a basic XMLRPC Client in PHP. It all works, but I'm having some serious issues trying to get consistent responses from method calls - Sometimes I get an XML array to n'th depth based on the verbosity of the output of the command I run, sometimes its a XML struct, and sometimes its just a plain old value. Then I've got errors to deal with - It seems the XMLRPC standard has a Fault struct with 'faultCode' and 'faultString' values it responds with, which is great because thats tidy and I can pull that data out via the named key in the XML. But you only get that struct if error is from the shell itself (For example if the called command had a bad argument), whereas an error coming from the command has to be just a normal XML response.
How can I possibly write a robust web-service around what appears to be such varied replies from the XMLRPC server? What I'd really like to do is have the exact same XML struct reply back every time with the same Keys (returnCode (0=success, >1=error), returnValue/s).
Thanks for any advice.

Maybe start with an existing XML/RPC client and let the client do the protocol legwork. There is Zend\XmlRpc in Zend Framework but also standalone clients like fxmlrpc.

Related

Feed data to remote process

I am not really sure how to phrase my question, but I'll try to be as clear as possible.
I want to create a demo website which allows people to input sentences which are then sent to a remote host, and classified in a Python script on that host. Basically, the Python script, when initialised, needs to load some big classifier files into NLTK classifier objects, which is preferably done only once to save time. So I would like to keep these objects alive. I realise I can execute a while loop in order to wait for any incoming data. The loop would parse the data and do whatever with it:
#pseudocode for Python script
while True:
if(some_remote_input){
parse, classify, etc.;
}
My question: What is a recommended package to collect data sent remotely? socket, perhaps?
And how would I go about this in PHP/AJAX? The desired procedure is like this:
User enters a sentence in the web app
Sentence is validated/prepared
Sentence is sent to remote host as input for python script (which is always running (like a server)
The result of the python classification script is returned to the website
Results are formatted and printed to the user
I am concerned about step 3.
I prefer not to integrate the Python environment on the server where the website is hosted, as there is not a lot of free space and it requires a lot of annoying packages.
If you need any more info, please let me know!
What you are looking for is a message broker or message queue system.
There are several message brokers available:
RabbitMQ
Kafka
AMQ
This lets you pipe data betwen the message transmitters (web server) and message consumers (the natural language processing pipeline) in a way that is agnostic to what technologies are used in the web server and the NLP-pipeline

Returning executable PHP code from a web service (a la JSON)

I'm working on a web service that exchanges XML data messages - which works for your typical desktop and mobile application.
However, one of the web service's clients is a PHP website and my analysis of execution shows a lot of time is spent in reading the XML returned from the service. I'm wondering if it might be faster if the service returns executable PHP code directly that could be put through eval().
I know that eval() is slower than "native" PHP when you have a PHP accelerator installed, but as far as I know, we don't.
Has anyone adopted this tactic?

CORBA broker / proxy over HTTP or accessible via sockets (for PHP)?

I'm looking at connecting an existing PHP codebase to a remote CORBA service. All actual data is passed via XML so I don't think I need an IDL to PHP mapping for remote invocation. I just need to connect to the CORBA service, transmit to it the XML string, and read the XML response.
After some research on this I found the CORBA4PHP PHP extension which I'm about to try although am having some reservations (last updated in 2009). I also found numerous implementations in Java and Python.
To avoid dealing with a new PHP extension I'm wondering if there exists a CORBA HTTP proxy of sorts in any language that would take care of communicating with the CORBA service. I would HTTP POST to the proxy (or some socket communication), it would relay it to the CORBA service, and relay back to me its response.
Does such a proxy exist?
I don't know of such a service, but perhaps others might know of one. That said, given how simple your IDL is, I would just go ahead and try the CORBA4PHP extension and use that if it works.
If it doesn't work (I've no idea about its quality), it would be really simple to build such a proxy yourself:
Download a free ORB (let's say you get one for Java, say JacORB)
Compile your IDL and build a client to the CORBA service
Add a front-end API to your Java application which your PHP code will use to call it and pass in the string parameter containing your XML (POST sounds reasonable, and there are plenty of ways to implement such a thing in Java)

SOAP PHP server-side debugging

I was landed a project to debug a PHP SOAP server (SoapServer) written by an unknown party. It is being used by a c# SOAP client, which I don't have access to the source code to (in other words, I cannot use __getLastResponse to see what it gets). I am trying to capture XML output of the server's responses. Traffic sniffing (wireshark, etc) doesn't work because of the SSL layer being used to encrypt XML messages. Any help in figuring out how to see the XML messages sent out by the server would be greatly appreciated.
There's an excellent example for extending the SoapServer class and grabbing the Soap XML request and responses here: http://blog.mayflower.de/archives/179-Extending-class-SoapServer-PHP5-for-debugging.html
Does the SoapServer look like this one, or like this one? If it's the former, you're up a tree and every ladder within a year's distance has been violently destroyed by wolverines. Rather, it's a binary blob of compiled code from which there is no escape.
If it's the latter, you may have some hope -- the service method's third parameter can be set to true to get the response data rather than blindly sending it out.
There's also a rumor that the ancient "nuSOAP" library has a server mode, but that project seems to have imploded in upon itself, and took the documentation with it.
Long-term, you may be better served by using a web service layer that isn't pathologically backwards, though that might not be an option for you.

Calling a Python program from PHP

I've got a version of the A* algorithm that builds a graph of the
UK road and cycle network in Python lists. It takes about 30 seconds
to initialise, but once done can very quickly find the shortest route
between any two vertices. The start and finish vertex ids are provided
by PHP.
I'm trying to work out the best way of communicating between
PHP and the Python program. I only want to do the initialisation phase
when the Apache server starts, so my question is: How do I keep the
python program alive and request routes from it via php? I have a
GLAMP setup.
Easiest way that I can think of would be XMLRPC. Python makes it horribly easy to set up an XMLRPC server, and there's php_xmlrpc for bindings on the PHP side...
def calculate_path(v1, v2):
return [v1, ..., v2]
from SimpleXMLRPCServer import SimpleXMLRPCServer
server = SimpleXMLRPCServer(('localhost', 9393))
server.register_function(calculate_path)
server.serve_forever()
and you're running and should be able to do an XMLRPC call for calculate_path on http://localhost:9393/ from your PHP app.
Check this question out: Calling Python in PHP
Also check out this extension: http://www.csh.rit.edu/~jon/projects/pip/
I don't know if you're hosting environment allows you to add new php extensions, but you get the idea.
I would make a "backend" server from your Python application. There are many ways to call into the Python application:
Thrift and protocol buffers
HTTP (CherryPy is simple to get cranking) with XML or JSON
XMLRPC in Python
Raw sockets
This avoids any startup penalty for the Python application.
You could do something as simple as a REST web server in Python using web.py:
http://webpy.org/
and then call that via PHP, should make the whole task super simple.
See this for more info:
http://johnpaulett.com/2008/09/20/getting-restful-with-webpy/

Categories