问题描述
我有一个命名管道文件,如下所示:
I have a named pipe file that looks like this:
prw-r--r-- 1 root root 0 Aug 11 17:01 /tmp/debug
当我在PHP中执行以下操作时:
When I do something like this in PHP:
$fp = fopen("/tmp/debug", "r");
它挂起(即永不返回).有没有办法使此呼叫返回和/或超时?
It hangs (i.e. never returns). Is there a way to make this call return and/or timeout?
(编辑)
请注意,我希望一个进程使用写入权限打开此管道,而另一个进程使用读取权限打开管道.有人在向该管道写入数据,而其他人正在从该管道读取数据.问题是读者有时会挂在fopen()上,无论是否成功,我总是要返回它.
Note that I want one process opening this pipe with write permissions, and another process opening the pipe with read permissions. Someone is writing to this pipe while someone else is reading from this pipe. The issue is that the reader is sometimes hanging on the fopen() -- which I always want to return, whether it was successful or not.
推荐答案
http://php.net/manual/en/function.stream-set-timeout.php
请注意:
也许这会有所帮助.
此外,请阅读此帖子
这篇关于在PHP中打开命名管道时如何防止fopen()挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!