I have to open a named fifo from a php script that needs to write to the fifo, but it may not always be opened on the read end. Now I'm using fopen
, but it always blocks when the read end of the fifo it's not opened. Is there an equivalent of the UNIX's int open(pname, O_WRONLY | O_NONBLOCK)
in php so that when the fifo it's not opened to return imediately?
No direct equivalent to the C function you describe. But you could use:
fopen($pipename, "w+")
The operation will return immediately, because it obtains read/write access to the pipe, so a read handle will always be opened (Opening plain write access the pipe will block for a reader to open the other end)
Note: Usually people do not want to do this. There is no way to know if the real pipe reader actually got the message or not. This might result to data loss.
Named pipes are best suited in applications where it can be guaranteed that both writer and reader run in parallel.