Interfacing PHP and Python on Apache

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Any suggestions on having python and php scripts communicate with each
other on the same apache server? My setup is like:

PHP Web Page(on apache) ---> Python Gdata Consumer -----> Gdata
and then json is returned back like:
PHP Web Page<----json data---- Pthon Gdata Consumer

Oh, and I can't use python's C extension or pyphp (boss vetoed both
ideas). Any alternative to making http calls between them? Suggestions

Re: Interfacing PHP and Python on Apache

nicodotti2 schreef:
Quoted text here. Click to load it


2 possibilities that might help:

1) commandlinestyle Python invocation:
Maybe you can call your Pythonscripts commanline style
(exec/passthru/etc) and use the output?

2a) Http (simple)
Of course, like you suggested, you can also make http-calls and catch
the output. For simple calls (no POSTdata) you can suffice with a simple
get, eg:
$myPython = "http://localhost/pyth/";
// If you want you can add name/value pairs here.
$content = file_get_contents(urlencode($myPython));

2b) Http (complex)
If your needs are more complex (eg lots of data, authentication,
cookies, etc), then use CURL.

Erwin Moller

Re: Interfacing PHP and Python on Apache

Quoted text here. Click to load it

What do you need each of the scripts to do?  Perhaps a simple REST/
SOAP setup could help, depending on requirements.  Getting structured
XML back is quite versatile and you might find you can expose the web
service to your customers directly, if applicable.

Depends on what you are doing though, but I would explore REST and see
if this fits your needs.



Site Timeline