我正在使用斯坦福命名空间,但在斯坦福标签中有此警告.php
警告:proc_open(): 创建进程失败,错误代码 - 0
这是由这条线引起的
$process = proc_open($cmd, $descriptorspec, $pipes, dirname($this->getJar()));
我不知道如何解决它。
我查看了 php 文档中的示例,我也遇到了完全相同的错误(我在使用 WAMP 的 Windows 上)。
经过一番挖掘,我发现我可以通过省略目录和环境参数来解决问题,例如 - 这对我有用:
<?php
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
1 => array("pipe", "w"), // stdout is a pipe that the child will write to
2 => array("file", "error-output.txt", "a") // stderr is a file to write to
);
$cwd = 'D:/wamp/www/test';
$env = array('some_option' => 'aeiou');
$process = proc_open('php', $descriptorspec, $pipes, /* $cwd, $env */ );
if (is_resource($process)) {
// $pipes now looks like this:
// 0 => writeable handle connected to child stdin
// 1 => readable handle connected to child stdout
// Any error output will be appended to /tmp/error-output.txt
fwrite($pipes[0], '<?php print_r($_ENV); ?>');
fclose($pipes[0]);
echo stream_get_contents($pipes[1]);
fclose($pipes[1]);
// It is important that you close any pipes before calling
// proc_close in order to avoid a deadlock
$return_value = proc_close($process);
echo "command returned $return_value'n";
}
?>
因此,您可以尝试从以下位置更新代码吗:
$process = proc_open($cmd, $descriptorspec, $pipes, dirname($this->getJar()));
自:
$process = proc_open($cmd, $descriptorspec, $pipes);
如果这对您有用,那么问题出在代码的这一行dirname($this->getJar())
。此路径不存在或无法访问。
您是否对dirname($this->getJar())
进行了var_dump()
并检查该路径是否存在?
上面的示例也通过像这样设置当前工作目录来修复:
$process = proc_open('php', $descriptorspec, $pipes, getcwd(), $env );
根据文档:
CWD
命令的初始工作目录。这必须是绝对目录路径,或者 NULL 如果要使用默认值(当前 PHP 进程的工作目录)