--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Either approach sounds reasonable to me. I don't know anything about PHP either so I may be naïve thinking that PHP can run equally well as a CGI or a command-line script. If you go with #2, you can connect an IOStream to a unix socket.For example, look in UnixSocketTest in the Tornado source. There's a server in that test that binds to a Unix socket, but that's not the part you want to look at. Instead, examine the client code around here:stream = IOStream(socket.socket(socket.AF_UNIX))
On Fri, Dec 13, 2013 at 1:51 PM, Ethan Collins <collins...@gmail.com> wrote:
I have a tornado app for ecommerce and need to connect the payment gateway code. My provider has provided me only PHP supported library for this payment gateway. It has 2 APIs, 1 to connect with the payment gateway server to get the user redirection URL (this consumes ~400ms due to the network roundtrip) and the second one is a callback API. Think of this as synonymous to the Facebook auth code in Tornado, at a high level.
I currently intend to call the PHP code from my python handlers. There are 2 ways as I have found.
1) Use subprocess module, like as mentioned here: https://mail.python.org/pipermail/tutor/2009-October/071973.html
2) Run PHP-FPM on the backend and push requests to it via unix sockets. I find this method for convenient, more so because it will have less invocation cost and I belive several calls to the unix sockets can be done simultaneously (hoping that socket calls will be asynchronous, need to find out) if need arises.
My Queries:
1) Has anyone tried to call PHP code from their python code? Are there any challenges that I need to take care of? (I don't know PHP, first timer)
2) If unix sockets cannot be called asynchronously, then I have to choose the option #1 but then I also need to use the decorator @tornado.web.asynchronous. Can this decorator be used over subprocess module? If possible, anything specific that I need to take care of? (till now I didn't have the need to use this decorator in my code, so really don't know)
Will be great if I can get your comments/viw here.
Cheers,
Ethan
Rereading your initial post, I have a new thought. So, does PHP-FPM speak HTTP over the Unix socket, or does it speak some other protocol? If it's just an HTTP server, you should reconfigure PHP-FPM to listen on a TCP/IP socket and use Tornado's AsyncHTTPClient to talk with it. If it's speaking a protocol other than HTTP then that won't work, of course....
On Sat, Dec 14, 2013 at 1:28 PM, A. Jesse Jiryu Davis <je...@emptysquare.net> wrote:Rereading your initial post, I have a new thought. So, does PHP-FPM speak HTTP over the Unix socket, or does it speak some other protocol? If it's just an HTTP server, you should reconfigure PHP-FPM to listen on a TCP/IP socket and use Tornado's AsyncHTTPClient to talk with it. If it's speaking a protocol other than HTTP then that won't work, of course....I think you can do HTTP over unix sockets with SimpleAsyncHTTPClient if you pass in a custom Resolver that returns an AF_UNIX address for some fake hostname. However, I'd only recommend this if you're running into problems running it over TCP (e.g. port allocation headaches or a need for better security against other users on the same machine).
Overall, my recommendation for foreign code like this would go in this order:1) Port it to python. It's easier to interface with a well-designed API directly than to build an ad-hoc cross-language interface.
2) Run the foreign code in a subprocess (but watch out for shell injection and other potential security issues). PHP has a usable command-line mode, although running it in a subprocess is likely to be slower than a server-based option due to interpreter startup.