Page 1 of 1

Problem with running python script from PHP

Posted: Tue May 04, 2010 10:45 am
by pratikpotnis
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?

Re: Problem with running python script from PHP

Posted: Tue May 04, 2010 3:24 pm
by Christopher
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.

Re: Problem with running python script from PHP

Posted: Tue May 04, 2010 10:06 pm
by pratikpotnis
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.
Thanks Christopher.

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

Posted: Wed May 05, 2010 12:54 am
by Weirdan
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.