title: Named pipe in php on Windows/Mac/Linux?
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Here are the links I have found so far:</p>
  
  <p><a href="http://bytes.com/topic/php/answers/557245-named-pipes-windows" rel="nofollow noreferrer">http://bytes.com/topic/php/answers/557245-named-pipes-windows</a></p>
  
  <p><a href="https://bugs.php.net/bug.php?id=29005" rel="nofollow noreferrer">https://bugs.php.net/bug.php?id=29005</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3623198/interprocess-communication-using-named-pipes-in-c-sharp-php">Interprocess Communication using Named Pipes in C# + PHP</a></p>
  
  <p><a href="http://en.wikipedia.org/wiki/Named_pipe#In_Windows" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Named_pipe#In_Windows</a></p>
  
  <p><a href="http://www.phpkode.com/source/p/xp-framework/xp-framework-xp-framework-554d8b2/core/src/main/php/rdbms/mysqlx/NamedPipe.class.php" rel="nofollow noreferrer">http://www.phpkode.com/source/p/xp-framework/xp-framework-xp-framework-554d8b2/core/src/main/php/rdbms/mysqlx/NamedPipe.class.php</a></p>
  
  <p>I've tried each of these in php 5.3.13 but none of them work:</p>
  
  <pre><code>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+"));
  </code></pre>
  
  <p>I always get an error that looks like this:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>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.</p>
  
  <p>Bonus points if you can supply cross-platform code, perhaps using posix_mkfifo() or system("mkfifo pipe") like in this answer:</p>
  
  <p><a href="http://www.php.net/manual/en/function.popen.php#22801" rel="nofollow noreferrer">http://www.php.net/manual/en/function.popen.php#22801</a></p>
  
  <p>Ideally the solution should work with a vanilla install of php, so without sockets, etc, but anything helps thanks.</p>