Bishal
Bishal

Reputation: 837

popen() in php works from command line but not from browser

I have a simple php script which parses the user input from html form. Since Python does string processing so well, I actually wrote the parser in python. So I forward the user entered string to python script for processing using

    $query = "avocados"; // from HTML form 
    $handle = popen("./NLParser.py $query","r");
    $read = fread($handle,2048);
    pclose($handle);

when I execute the php from command line interpreter, I get the desired output. But when I visit the same php file from a browser, I get empty string from fread(). I tried checking if the $handle is FALSE and I also read from stderr, no problems there. Please help me figure out this inconsisteny.

I tried running

phpinfo();

The php.ini file used by command line php interpreter was

Loaded Configuration File => /etc/php5/cli/php.ini

and the same entry on web was

Loaded Configuration File   /etc/php5/apache2/php.ini

I am using Ubuntu 14.04.1 LTS with PHP Version 5.5.9-1ubuntu4.4. All the files have permission set to 755

Upvotes: 2

Views: 1103

Answers (1)

Raed
Raed

Reputation: 698

Try changing the owner and group of NLParser.py to the ones of your server.

Upvotes: 1

Related Questions