Problem with running python script from PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pratikpotnis
Forum Newbie
Posts: 4
Joined: Mon Nov 23, 2009 5:50 am

Problem with running python script from PHP

Post 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?
User avatar
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

Post 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.
(#10850)
pratikpotnis
Forum Newbie
Posts: 4
Joined: Mon Nov 23, 2009 5:50 am

Re: Problem with running python script from PHP

Post 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?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Problem with running python script from PHP

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