开发者

How can I open a named pipe?

  • 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.ne开发者_运维技巧t/manual/en/function.shell-exec.php#52826


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜