title: bash echoing value to process, php loop (the process) not reading stdin
body: <h2>Background:</h2>
  
  <p>I'm in a position where I'm placing data into the command line and I need a php loop (what will become a server of sorts) to read STDIN and just echo what it reads to the shell its running in.</p>
  
  <p>The following terrible code works when the process is running in the same shell as the content echoed:</p>
  
  <pre><code>&lt;?php
  
  echo getmypid();
  $string = "/proc/" . getmypid() . "/fd/0";
  while (true) {
  
      fwrite(STDOUT, fgets(fopen($string, 'r'), 4096) . " worked\n");
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>I've tried many variants:</p>
  
  <pre><code>&lt;?php
  
  echo getmypid();
  $string = "/proc/" . getmypid() . "/fd/0";
  while (true) {
  
      $fo = fread(STDIN, 1024);
      fwrite(STDOUT, $fo);
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>The problem is that whenever I write to this loop from a separate terminal, the output appears in the other terminal but is not processed by the loop.</p>
  
  <p>When I enter text in the same terminal, the text is echoed right back.</p>
  
  <p>I need a way to get command line data into this loop from any source. </p>