Hi I have a python code performing some computation for me.I have a html page which passes certain argumnets to a php page.This php page needs to pass on the value to the Python class and get the result back. How do I go about this??
On Wed, Apr 23, 2008 at 11:09:53AM -0700, vijay wrote: > Hi > I have a python code performing some computation for me.I have a > html page which passes certain argumnets to a php page.This php page > needs to pass on the value to the Python class and get the result > back. > How do I go about this??
> Hi > I have a python code performing some computation for me.I have a > html page which passes certain argumnets to a php page.This php page > needs to pass on the value to the Python class and get the result > back. > How do I go about this??
Write a commandline-app in python, that does the work for you. Invoke that using php.
Or use something like pyphp - but I haven't used it, can't comment on its usability/support etc.
> > Hi > > I have a python code performing some computation for me.I have a > > html page which passes certain argumnets to a php page.This php page > > needs to pass on the value to the Python class and get the result > > back. > > How do I go about this??
> Write a commandline-app in python, that does the work for you. Invoke > that using php.
> Or use something like pyphp - but I haven't used it, can't comment on > its usability/support etc.
> Diez
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'); ?>
I would look into pyphp though. This method has so many issues attached to it it's hardly worth bothering with. I'm with Nick when I say why on earth are you needing to call Python from within PHP as opposed to using only Python or only PHP?
On Wed, 23 Apr 2008 20:42:44 +0200, Diez B. Roggisch wrote: > vijay schrieb: >> Hi >> I have a python code performing some computation for me.I have a >> html page which passes certain argumnets to a php page.This php page >> needs to pass on the value to the Python class and get the result >> back. >> How do I go about this??
I do this quite a bit:
<?php
#***** GET OUTPUT OF PYTHON PROGRAM ***** $command = "/some/directory/report.py arg1 arg2 2>&1"; $p = popen($command, 'r');
> 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'); > ?>
What is rubbish about that - except from the obvious cleansing of input variables that has to take place? Python has a whole module dedicated to that rubbish, called subprocess.
> I would look into pyphp though. This method has so many issues > attached to it it's hardly worth bothering with. > I'm with Nick when I say why on earth are you needing to call Python > from within PHP as opposed to using only Python or only PHP?
While I certainly prefer to use Python wherever I can, that does not mean that there aren't cases where legacy systems or other constraints make this impossible. If I have e.g. a type3-based website - "how on earth" should I replace that with Python (without wasting a lot of time)?
> While I certainly prefer to use Python wherever I can, that does not mean > that there aren't cases where legacy systems or other constraints make this > impossible. If I have e.g. a type3-based website - "how on earth" should I > replace that with Python (without wasting a lot of time)?
I don't understand how the 2 are mutually exclusive?
You can have PHP and Python bindings installed on the same Apache server, unless I'm mistaken?
On Apr 24, 5:51 am, Nick Stinemates <n...@stinemates.org> wrote:
> I don't understand how the 2 are mutually exclusive?
> You can have PHP and Python bindings installed on the same Apache > server, unless I'm mistaken?
Not everyone have the luxury of having mod_python installed. It depends on the host. On the other hand, mod_php will almost certainly be installed on any Apache server.
>> While I certainly prefer to use Python wherever I can, that does not mean >> that there aren't cases where legacy systems or other constraints make this >> impossible. If I have e.g. a type3-based website - "how on earth" should I >> replace that with Python (without wasting a lot of time)?
> I don't understand how the 2 are mutually exclusive?
> You can have PHP and Python bindings installed on the same Apache > server, unless I'm mistaken?
What about having to set up & maintain (which might not even possible on a cheap hoster) two configs for that - just for having a few lines of python being run? And how do you go about session-state sharing and so forth? After all the scipt might need to be access controlled based on login state.
I don't say that there aren't options to run python more direct. I argumented against a rather bold statement of Mr. alexelder:
""" 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: """
> 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.
> > 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.
Thanks for pointing that out. I thought the warning before hand could've suggested that this implementation wasn't the best. I'll be more explicit in the future.
> > 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:
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.
On Fri, Apr 25, 2008 at 03:29:49PM +0200, Diez B. Roggisch wrote: > Nick Stinemates schrieb: >>> While I certainly prefer to use Python wherever I can, that does not mean >>> that there aren't cases where legacy systems or other constraints make >>> this impossible. If I have e.g. a type3-based website - "how on earth" >>> should I replace that with Python (without wasting a lot of time)? >> I don't understand how the 2 are mutually exclusive? >> You can have PHP and Python bindings installed on the same Apache >> server, unless I'm mistaken?
> What about having to set up & maintain (which might not even possible on a > cheap hoster) two configs for that - just for having a few lines of python > being run? And how do you go about session-state sharing and so forth? > After all the scipt might need to be access controlled based on login > state.
> I don't say that there aren't options to run python more direct. I > argumented against a rather bold statement of Mr. alexelder:
> """ > 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: > """
>> > 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:
> 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.
You mean opening a local-loop socket instead of a anonymous socket, hogging at least another apache process and then possibly spawning another process if the python-script is implemented as real CGI - not fast_cgi or python - is the better solution? I doubt that. More wasteful in all aspects, with small to any gain at all.
Unix uses pipes as IPC all the time. I fail to see why that is "rubbish".