1

I have a Python application (command line tool running on a machine M1) that has input I1 and output O2. Also, I have a PHP application (website running on a machine M2) that feeds the Python application with input I1 and expects to read the output O1. My question is what's the best approach to solve this problem? (the environment is GNU/Linux)

I was thinking at a solution with ssh; the PHP script executes a command via ssh: "ssh M2:./my_script.py arguments output_file" and transfers the output file "scp M2:output_file ." from M2 to M1. But, I don't think this solution is elegant. I was thinking of web services (the Python application should expose a web service), but I'm not sure what's the complexity of this solution or if it works.

Thanks,

2
  • Actually a webservice interface adds complexity. The SSH pipe is the optimal solution. (An inetd service would also be possible, but usually too much of a security issue.) Commented Nov 29, 2010 at 15:37
  • I disagree, as a SSH pipe is very inflexible, for example if Laurentiu's website becomes big, it would be almost impossible for him to dispatch the php server's requests to a cluster of machines, whereas an xmlrpc server or something similar allows him the possibility of routing to different machines. Commented Nov 29, 2010 at 15:54

4 Answers 4

1

Like others above, I'd do it by implementing a web service rather than fiddling with SSH. You're right that the SSH solution is inelegant.

The obvious answer for what to build your Python web application on top of: Django. If you want to use something lighter, look at a microframework like Flask.

For data interchange, JSON is your best bet -- supported by both Python and PHP now.

Sign up to request clarification or add additional context in comments.

1 Comment

Your solution seems good, but it creates the need for a web server (e.g. Apache) on machines. I will consider it for implementation.
0

I think you should implement a web service . I don't know how to do it with python but i suppose it would be fairly easy.

Comments

0

Setup a small server on M1 using twisted (or something similar), that runs the command when hit with an xml request. Then return the ouput to the php side. So the php just sends a request with input1 to M1, and M1 returns a response with O1 (or O2? Your abbreviation are confusing :P). It's very KISS, and should scale fairly well. I have no idea how the php side would work, but twisted is extreamly well documented. Have a look at this link for some idea on how to set up a simple twisted server.

1 Comment

O1 = O2, sorry for confusion. Thanks for the tip.
0

If O1 = O2 you could let them communicate with a binary protocol over a file-socket. Like Hessian or Thrift. Given that you run your apps on a *nix server it should be very fast.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.