Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Calling Python code from inside php
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  16 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
vijay  
View profile  
 More options Apr 23 2008, 2:09 pm
Newsgroups: comp.lang.python
From: vijay <gvijaysrini...@gmail.com>
Date: Wed, 23 Apr 2008 11:09:53 -0700 (PDT)
Local: Wed, Apr 23 2008 2:09 pm
Subject: Calling Python code from inside php
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??

Cheers
Vijay


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Stinemates  
View profile  
 More options Apr 23 2008, 2:40 pm
Newsgroups: comp.lang.python
From: Nick Stinemates <n...@stinemates.org>
Date: Wed, 23 Apr 2008 11:40:32 -0700
Local: Wed, Apr 23 2008 2:40 pm
Subject: Re: Calling Python code from inside php

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??

> Cheers
> Vijay
> --
> http://mail.python.org/mailman/listinfo/python-list

Why not just write it all in Python?

--
Nick Stinemates (n...@stinemates.org)
http://nick.stinemates.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options Apr 23 2008, 2:42 pm
Newsgroups: comp.lang.python
From: "Diez B. Roggisch" <de...@nospam.web.de>
Date: Wed, 23 Apr 2008 20:42:44 +0200
Local: Wed, Apr 23 2008 2:42 pm
Subject: Re: Calling Python code from inside php
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??

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
MC  
View profile  
 More options Apr 23 2008, 3:08 pm
Newsgroups: comp.lang.python
From: MC <XX.X...@XX.XmclaveauX.com>
Date: Wed, 23 Apr 2008 21:08:10 +0200
Local: Wed, Apr 23 2008 3:08 pm
Subject: Re: Calling Python code from inside php
Hi!

If you are under Windows, you can:
 - call Python's functions via Active-Scripting
 - call a Python COM server (functions or properties)

For that, use Pywin32. And, in all cases, call functions can use
parameters.

--
@-salutations

Michel Claveau


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
alexel...@gmail.com  
View profile  
 More options Apr 23 2008, 3:13 pm
Newsgroups: comp.lang.python
From: alexel...@gmail.com
Date: Wed, 23 Apr 2008 12:13:40 -0700 (PDT)
Local: Wed, Apr 23 2008 3:13 pm
Subject: Re: Calling Python code from inside php
On Apr 23, 7:42 pm, "Diez B. Roggisch" <de...@nospam.web.de> wrote:

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?

Alex.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tobiah  
View profile  
 More options Apr 23 2008, 3:17 pm
Newsgroups: comp.lang.python
From: Tobiah <t...@tobiah.org>
Date: Wed, 23 Apr 2008 12:17:06 -0700
Local: Wed, Apr 23 2008 3:17 pm
Subject: Re: Calling Python code from inside 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');

$output = fread($p, 1024 * 1024);

print $output;

?>

** Posted from http://www.teranews.com **


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options Apr 23 2008, 3:35 pm
Newsgroups: comp.lang.python
From: "Diez B. Roggisch" <de...@nospam.web.de>
Date: Wed, 23 Apr 2008 21:35:43 +0200
Local: Wed, Apr 23 2008 3:35 pm
Subject: Re: Calling Python code from inside php

> 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)?

Diez


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Stinemates  
View profile  
 More options Apr 23 2008, 11:51 pm
Newsgroups: comp.lang.python
From: Nick Stinemates <n...@stinemates.org>
Date: Wed, 23 Apr 2008 20:51:08 -0700
Local: Wed, Apr 23 2008 11:51 pm
Subject: Re: Calling Python code from inside 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)?

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?

--
Nick Stinemates (n...@stinemates.org)
http://nick.stinemates.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sturlamolden  
View profile  
 More options Apr 24 2008, 10:56 pm
Newsgroups: comp.lang.python
From: sturlamolden <sturlamol...@yahoo.no>
Date: Thu, 24 Apr 2008 19:56:14 -0700 (PDT)
Local: Thurs, Apr 24 2008 10:56 pm
Subject: Re: Calling Python code from inside php
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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options Apr 25 2008, 9:29 am
Newsgroups: comp.lang.python
From: "Diez B. Roggisch" <de...@nospam.web.de>
Date: Fri, 25 Apr 2008 15:29:49 +0200
Local: Fri, Apr 25 2008 9:29 am
Subject: Re: Calling Python code from inside php
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:
"""

Diez


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sturlamolden  
View profile  
 More options Apr 25 2008, 11:02 am
Newsgroups: comp.lang.python
From: sturlamolden <sturlamol...@yahoo.no>
Date: Fri, 25 Apr 2008 08:02:01 -0700 (PDT)
Local: Fri, Apr 25 2008 11:02 am
Subject: Re: Calling Python code from inside php
On Apr 23, 9:13 pm, alexel...@gmail.com wrote:

> 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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
alexel...@gmail.com  
View profile  
 More options Apr 25 2008, 1:37 pm
Newsgroups: comp.lang.python
From: alexel...@gmail.com
Date: Fri, 25 Apr 2008 10:37:23 -0700 (PDT)
Local: Fri, Apr 25 2008 1:37 pm
Subject: Re: Calling Python code from inside php
On Apr 25, 4:02 pm, sturlamolden <sturlamol...@yahoo.no> wrote:

> On Apr 23, 9:13 pm, alexel...@gmail.com wrote:

> > 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.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sturlamolden  
View profile  
 More options Apr 25 2008, 3:56 pm
Newsgroups: comp.lang.python
From: sturlamolden <sturlamol...@yahoo.no>
Date: Fri, 25 Apr 2008 12:56:21 -0700 (PDT)
Local: Fri, Apr 25 2008 3:56 pm
Subject: Re: Calling Python code from inside php
On Apr 23, 9:08 pm, MC <XX.X...@XX.XmclaveauX.com> wrote:

> If you are under Windows, you can:
>  - call Python's functions via Active-Scripting
>  - call a Python COM server (functions or properties)

> For that, use Pywin32. And, in all cases, call functions can use
> parameters.

This is perhaps the preferred solution if the web server is IIS and
not Apache.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Eric Wertman  
View profile  
 More options Apr 25 2008, 4:03 pm
Newsgroups: comp.lang.python
From: "Eric Wertman" <ewert...@gmail.com>
Date: Fri, 25 Apr 2008 16:03:28 -0400
Local: Fri, Apr 25 2008 4:03 pm
Subject: Re: Calling Python code from inside php

>  > 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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nick Stinemates  
View profile  
 More options Apr 25 2008, 6:36 pm
Newsgroups: comp.lang.python
From: Nick Stinemates <n...@stinemates.org>
Date: Fri, 25 Apr 2008 15:36:46 -0700
Local: Fri, Apr 25 2008 6:36 pm
Subject: Re: Calling Python code from inside php

Don't cry me the river, I was just asking about his situation.

If there's a specific problem with using python, then write it in PHP?!?

--
Nick Stinemates (n...@stinemates.org)
http://nick.stinemates.org


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Diez B. Roggisch  
View profile  
 More options Apr 26 2008, 2:44 pm
Newsgroups: comp.lang.python
From: "Diez B. Roggisch" <de...@nospam.web.de>
Date: Sat, 26 Apr 2008 20:44:09 +0200
Local: Sat, Apr 26 2008 2:44 pm
Subject: Re: Calling Python code from inside php
Eric Wertman schrieb:

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".

Diez


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »