I'm currently using proc_open() in php to communicate with command line tools. It automatically creates up to 3 file descriptors for STDIN, STDOUT and STDERR because more than 3 pipes breaks Windows compatibility. It works great on Windows XP and 10.7 on my Mac.
However, I would like to be able to create my own named pipes for better control. If I'm unable to do so, then I have to maintain references between the process resource and its stream resources, which is overly complicating my code. I can't use files because they fill up disk space for long tasks. I'm also trying to avoid using sockets because they aren't enabled by default in php.
Here are the links I have found so far:
http://bytes.com/topic/php/answers/557245-named-pipes-windows
https://bugs.php.net/bug.php?id=29005
Interprocess Communication using Named Pipes in C# + PHP
http://en.wikipedia.org/wiki/Named_pipe#In_Windows
I've tried each of these in php 5.3.13 but none of them work:
var_dump(fopen("\\\\.\\pipe\\mypipe", "w+"));
var_dump(fopen("\\\\127.0.0.1\\pipe\\mypipe", "w+"));
var_dump(fopen("\\\\".php_uname('n')."\\pipe\\mypipe", "w+"));
I always get an error that looks like this:
PHP Warning: fopen(\\.\pipe\mypipe): failed to open stream: No such file or directory in C:\Documents and Settings\Administrator\Desktop\named-pipe.php on line 15
PHP Stack trace:
PHP 1. {main}() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:0
PHP 2. fopen() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:15
Warning: fopen(\\.\pipe\mypipe): failed to open stream: No such file or directory in C:\Documents and Settings\Administrator\Desktop\named-pipe.php on line 15
Call Stack:
0.0018 431936 1. {main}() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:0
0.0018 432072 2. fopen() C:\Documents and Settings\Administrator\Desktop\named-pipe.php:15
bool(false)
So my question is, has anyone successfully opened a named pipe on Windows XP? If not, what versions of Windows support named pipes? I don't know if the pipe "file" descriptor needs to already exist, for example if it has to be created by mysql or other services.
Bonus points if you can supply cross-platform code, perhaps using posix_mkfifo() or system("mkfifo pipe") like in this answer:
http://www.php.net/manual/en/function.popen.php#22801
Ideally the solution should work with a vanilla install of php, so without sockets, etc, but anything helps thanks.