Calling Python code from inside php
Eric Wertman
ewertman at gmail.com
Fri Apr 25 16:03:28 EDT 2008
> > A simple yet dangerous and rather rubbish solution (possibly more of a
> > hack than a real implementation) could be achieved by using a
> > technique described above:
> >
> > <?php
> > echo exec('python foo.py');
>
> This will spawn a Python interpreter, and not be particularly
> efficient. You could just as well have used CGI.
I'm in a bit of a similar situation. I decided to use python to
solve problems where I could, in a more regimented fashion. For
instance, I have a set of functions in a script, table.py. After I
set up mod_python to handle requests to a single directory with
python, I can call this with:
<?php include("http://localhost/py/table/nodes"); ?>
embedded in the page. This is probably pretty hackish too, but at
least it doesn't spawn a new process, and I don't have to solve things
that aren't related to display with php.
More information about the Python-list
mailing list