proc_open 返回 false 但未写入错误文件 - 权限问题? [英] proc_open returns false but does not write in error file - permissions issue?

查看:23
本文介绍了proc_open 返回 false 但未写入错误文件 - 权限问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为该主题的新手,我设置了一个 Ubuntu 12 网络服务器,根目录是/var/www/包含我的脚本 index.php 和一个名为reduce"的子目录,其中包含一个二进制文件(计算机代数系统, 文件名也是reduce").

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").

使用 ssh,我可以以 root 和我的非管理员用户帐户登录,然后 cd 到/var/www/目录并通过执行./reduce/reduce"启动二进制文件.但是,如果我使用我的 index.php 文件做同样的事情,它就不起作用.这里是index.php的基本内容(基本取自[1]):

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!";

}

奇怪的是,没有创建 ./error.log 文件,我得到的唯一输出是proc_open 的返回值:false".这是为什么?一些权限问题?所有者、组和其他人对 index.php 以及二进制文件具有执行权限.有什么想法吗?

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?

谢谢延斯

[1] http://www.molecularsciences.org/PHP/proc_open_tutorial_and_examples

推荐答案

我自己发现了错误:文件 ./error.log 不存在.手动创建后,一切正常.

I found the mistake myself: the file ./error.log did not exist. After creating it manually, everything works fine.

这篇关于proc_open 返回 false 但未写入错误文件 - 权限问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆