3

I have a named pipe file that looks like this:

prw-r--r-- 1 root root 0 Aug 11 17:01 /tmp/debug

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?

(edit)

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.

user306517
  • 523
  • 8
  • 21
  • 1
    possible duplicate of [Why does my program hang when opening a mkfifo-ed pipe?](http://stackoverflow.com/questions/8507810/why-does-my-program-hang-when-opening-a-mkfifo-ed-pipe) – Havenard Aug 11 '14 at 18:24

1 Answers1

0

http://php.net/manual/en/function.stream-set-timeout.php

Pay attention on:

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

Maybe this will help.

Also, read this post How to use named pipes in PHP between different functions or even different processes without fork?

Community
  • 1
  • 1
fiction
  • 566
  • 1
  • 6
  • 21
  • 2
    Reading in binary mode is unrelated to `fopen` blocking. – Overv Aug 11 '14 at 18:31
  • stream_set_timeout() is called *after* you have done a successful fopen, my problem is I cannot get past the fopen. – user306517 Aug 11 '14 at 18:35
  • 3
    @user also, you can try `$fp = fopen("/tmp/debug", "rn");` n - non blocking, but its not documented and not working on some platforms (like windows) – fiction Aug 11 '14 at 18:47
  • "rn" works. @fiction - if you want to submit that as an answer, I will approve it as an accepted answer. – user306517 Aug 11 '14 at 20:55