在PHP中打开命名管道时如何防止fopen()挂起 [英] how to prevent fopen() from hanging when opening up a named pipe in PHP

查看:108
本文介绍了在PHP中打开命名管道时如何防止fopen()挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个命名管道文件,如下所示:

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

请注意:

注意:为了便于移植,强烈建议您在使用fopen()打开文件时始终使用'b'标志.

Note: For portability, it is strongly recommended that you always use the 'b' flag when opening files with fopen().

也许这会有所帮助.

此外,请阅读此帖子 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆