Hi,
I am running a python script from PHP.
Here is the flow -
I am using popen of PHP to call python script.
In this python script I am giving a call to a python module "xlrd" for excel file parsing. python code - workbook = xlrd.open_workbook(filename)
When flow comes to using this python module "xlrd", flow completely exits and scripts stop working. I get all the echo messages from python before this module is accessed and no messages are displayed after that.
When I run python script individually (through command line) it works just fine. Problem occurs only if PHP calls this script.
Is there a problem with PHP buffer in this? PHP is not able to load this in its buffer?
Is there any solution for this?
Problem with running python script from PHP
Moderator: General Moderators
-
pratikpotnis
- Forum Newbie
- Posts: 4
- Joined: Mon Nov 23, 2009 5:50 am
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Problem with running python script from PHP
It is not exactly clear what "When flow comes to using this python module" means. What output do you get? Have you tried the simpler exec()?
Remember that PHP runs as the webserver user, so the execution environment is different that from you shell account. Make sure that all paths are available or specify absolute paths.
Remember that PHP runs as the webserver user, so the execution environment is different that from you shell account. Make sure that all paths are available or specify absolute paths.
(#10850)
-
pratikpotnis
- Forum Newbie
- Posts: 4
- Joined: Mon Nov 23, 2009 5:50 am
Re: Problem with running python script from PHP
Thanks Christopher.Christopher wrote:It is not exactly clear what "When flow comes to using this python module" means. What output do you get? Have you tried the simpler exec()?
Remember that PHP runs as the webserver user, so the execution environment is different that from you shell account. Make sure that all paths are available or specify absolute paths.
By flow I mean execution flow. All the python script statements before "workbook = xlrd.open_workbook(filename)" are executed. But when it comes to executing this statement, execution stops.
You have a point that PHP execution environment is different. But all other python statements are executed. So shouldn't be a problem with Python path? right?
XLRD python module/package helps in loading whole excel sheet. I am wondering whether PHP buffer is not able to handle excel sheet opened by python?
Any solution for this?
Re: Problem with running python script from PHP
What kind of output you get from running the script from shell command line?
Judging by what you said above the problem is either with the script itself (how you use the module), python module you use or with the output and how you interpret it . Post your code if you're allowed to.
Judging by what you said above the problem is either with the script itself (how you use the module), python module you use or with the output and how you interpret it . Post your code if you're allowed to.