【发布时间】:2012-10-29 15:23:42
【问题描述】:
我在 linux mkfifo /tmp/myFIFO 中创建了一个管道,现在我将 chmod 设置为 777.. 然后我有一个 c 应用程序,它读取管道并将我写的内容输出到管道。
当我在 php 中这样做时,它可以工作..
$command = "echo 'helloworld' > myFIFO";
$process = proc_open($command, $descriptor, $pipes, $cwd, $env);
但是当我用 fwrite 来做时,例如
$out = fopen("/tmp/myFIFO","w");
fwrite($out,"hello");
fclose($out);
它根本不起作用。我在 linux 中的管道没有得到任何输出?.. 为什么 fwrite 不起作用?.. 谢谢
【问题讨论】:
-
你检查fopen是否成功了吗?它在失败时返回布尔值 false。例如
$out = fopen(...) or die('unable to open file');. -
你试过
$out = fopen("/tmp/myFIFO","a");追加而不是截断吗? -
等不及要试一试了。我会尽快更新你。
-
你确定你的路径/工作目录是正确的吗?您的
fopen()代码使用绝对路径,但您的proc_open()示例使用相对路径。 -
我无法打开文件..这是为什么?..我将 chmod 设置为 777 但为什么我无法打开它?
标签: php c linux named-pipes