I can’t seem to open a Windows named pipe more than once from PHP:
$pipe1 = fopen($pipeName, 'r+'); // (1)
fclose($pipe1);
$pipe2 = fopen($pipeName, 'r+'); // (2)
fclose($pipe2);
(1) succeeds, and I can write to the pipe or open a blocking read on it.
(2) fails with
fopen(\\.\pipe\encoding): failed to open stream: Invalid argument
The “invalid argument” seems to be referring to the mode, but I’ve tried all different combinations of modes between (1) and (2) with no difference. It also fails whether it’s in the same process or another process.
I’m creating the pipe with:
CreateNamedPipe("\\\\.\\pipe\\encoding", 3, 0, 5, 512, 512, 0, 0);
where ‘3’ makes it a read/write pipe and ‘5’ is the maximum number of instances that can be created. I’ve tried different combinations of arguments for CreateNamedPipe as well, to no avail.
Is there something special I’m missing about Windows named pipes?
“The server process must call DisconnectNamedPipe to disconnect a pipe handle from its previous client before the handle can be connected to another client by using the ConnectNamedPipe function.”