need advice on building core code for python and PHP

Graham Dumpleton Graham.Dumpleton at gmail.com
Thu May 24 19:01:02 EDT 2007


On May 25, 5:24 am, aspineux <aspin... at gmail.com> wrote:
> On 24 mai, 19:33, Szabolcs Nagy <nszabo... at gmail.com> wrote:
>
> > > Is there a way I could code the base (core) code in Python and have
> > > PHP call it?  I've really liked using SQLAlchemy and there are other
>
> > * quick and dirty solution:
> > in a shell:
> >   $ python yourscript.py <pipe_in >pipe_out
> > in the php script:
> >   fwrite(pipe_in, input_data);
> >   results = fread(pipe_out, sizeof_results);
>
> > * simple and nice solution:
> >   do not ever use php
>
> Write a CGI wrapper around your python script, and publish it using mod_python.
> And make the appropriate http requests from PHP.

You do not need mod_python to host CGI scripts written in Python, they
are two separate things.

Depending on the complexity of what you are doing, you might be better
off writing a backend server in Python that incorporates an XML-RPC
server. Your PHP script can then use XML-RPC client to communicate to
the backend Python server to do the real work. Over time you could
even transition your web pages to being done in Python instead. In
doing this your back end Python server doesn't have to change, you
just make XML-RPC calls from the Python code for the web pages in
place of where you would be doing it with PHP initially. You also
wouldn't be restricted to web based front ends, you could also use GUI
based front end as well.

Graham




More information about the Python-list mailing list