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,
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.