如何打开命名管道?
- Ubuntu 9.10 / CentOS 5.5
- PHP 5.2.10-2ubuntu6.7 / 5.2.11
以下最小测试用例给出以下输出:
字符串(3)“foo”
警告:stat() [function.stat]:第 10 行 /[...]/mkfifo.php 中资源 id #3 的统计失败
布尔(假)
<?php
$pipe_name = 'foo';
if(!file_exists($pipe_name) && !posix_mkfifo($pipe_name, 0777)){
echo 'foo';
exit(1);
}
var_dump($pipe_name);
$pipe = fopen($pipe_name, 'r+');
var_dump(stat($pipe));
?>
当然我做错了什么?我使用 r+ 是因为它据称“对我有用” http://php .net/manual/en/function.posix-mkfifo.php#89642 但正如你所看到的,我什至没有机会做非阻塞部分。我还没有尝试过的替代、更详细的解决方案: http:// php.net/manual/en/function.shell-exec.php#52826
- Ubuntu 9.10 / CentOS 5.5
- PHP 5.2.10-2ubuntu6.7 / 5.2.11
The following minimal testcase gives this output:
string(3) "foo"
Warning: stat() [function.stat]: stat failed for Resource id #3 in /[...]/mkfifo.php on line 10
bool(false)
<?php
$pipe_name = 'foo';
if(!file_exists($pipe_name) && !posix_mkfifo($pipe_name, 0777)){
echo 'foo';
exit(1);
}
var_dump($pipe_name);
$pipe = fopen($pipe_name, 'r+');
var_dump(stat($pipe));
?>
Surely I'm doing something wrong? I used r+ because it's supposedly "works for me" per http://php.net/manual/en/function.posix-mkfifo.php#89642 but as you can see I don't even get a chance to do the non-blocking part. Alternative, more verbose solution that I haven't tried yet: http://php.net/manual/en/function.shell-exec.php#52826
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您的错误完全是由于在那里使用
stat()
引起的。您给它一个打开的文件资源,但它只能与$filename
一起使用。Resource id #3
证明您的管道已正确打开。使用
stat($pipe_name)
获取有关 fifo 的信息。或者
stream_get_meta_data($pipe)
用于打开的文件句柄。I think your error is soleley caused by using
stat()
there. You give it an opened file resource, but it should be used with a$filename
only.Your pipe was correctly opened as evidenced by
Resource id #3
Use
stat($pipe_name)
to get informations about the fifo.Or
stream_get_meta_data($pipe)
for the opened file handle.