views:

31

answers:

3

I have a webapp, created using CakePhp. I need to interface with a Python script. What is the best way to go about doing that? (I could use pipe etc., but I want to check what the best practices are)

Thanks.

A: 

First of all, check what kinds of syndication CakePHP offers. It may expose part of its API through xmlrpc, json, RSS, and so on.

If that's not an option, connect directly to the same database the CakePHP application uses. Or alternatively, implement some php code within your CakePHP framework that expors relevant data as JSON and interface with it.

Ivo van der Wijk
A: 

It really depends what you're looking for. If you are going to be interfacing with python extensively, then I would recommend looking into an XML-RPC solution. Details on how to configure an XML-RPC server using Twisted (Python) can be found here:

http://twistedmatrix.com/documents/10.1.0/web/howto/xmlrpc.html

Documentation on creating an XML-RPC client in PHP:

http://devzone.zend.com/article/1307

This solution may not be the cake-iest solution, but it works well as a vendor. If what your looking for is more of a one off type of deal, then using exec() would be much easier, though not the cleanest way.

JoeyP
I should note, never ever use exec() with an argument containing user input.
JoeyP
A: 

What sort of interface? Two way? One way?

I haven't done this as I'm not a Python programmer (yet), but there are many ways to expose/access cake - URL/param/param , POST, GET, RSS, whatever.

Take a look at the request handler: http://book.cakephp.org/view/1292/Obtaining-Request-Information

I don't know whether you're a Python or a CakePHP programmer, but if you're the former, the book: http://book.cakephp.org does tend to cover most things and is fairly logically laid out (whatever CodeIgniter/Symphony/Kohana fans might say).

Leo