问题
Being kind of new to the subject, I have set up an Ubuntu 12 webserver, root directory is /var/www/ containing my script index.php and a subdirectory called "reduce" that contains a binary (a computer algebra system, file name is also "reduce").
Using ssh, I can log in as root and my non-admin user account and cd to the /var/www/ directory and launch the binary by executing "./reduce/reduce". However, if I do the same thing from withing my index.php file, it does not work. Here is the essential content of index.php (basically taken from [1]):
$descriptorspec = array(
0 => array("pipe","r"),
1 => array("pipe","w"),
2 => array("file","./error.log","a")
) ;
// define current working directory where files would be stored
$cwd = './' ;
// open reduce
$process = proc_open('./reduce/reduce', $descriptorspec, $pipes, $cwd) ;
echo "return value of proc_open: " . (($process === false) ? "false" : "true");
if (is_resource($process)) {
// anatomy of $pipes: 0 => stdin, 1 => stdout, 2 => error log
fwrite($pipes[0], 'load excalc $');
fclose($pipes[0]) ;
// print pipe output
echo stream_get_contents($pipes[1]) ;
// close pipe
fclose($pipes[1]) ;
// all pipes must be closed before calling proc_close.
// proc_close() to avoid deadlock
proc_close($process) ;
echo "success!";
}
The weird thing is that no ./error.log file is created and the only output I get is "return value of proc_open: false". Why is that? Some permissions issue? Owner, group, and others have execute permissions on index.php as well as the binary. Any ideas?
Thanks Jens
[1] http://www.molecularsciences.org/PHP/proc_open_tutorial_and_examples
回答1:
I found the mistake myself: the file ./error.log did not exist. After creating it manually, everything works fine.
来源:https://stackoverflow.com/questions/24805645/proc-open-returns-false-but-does-not-write-in-error-file-permissions-issue