title: PHP proc_open() pipes communication
body: <p>The context is the following:</p>
  
  <ul>
  <li>I'm using a Raspberry Pi with <code>PHP5</code> and <code>Apache</code> installed on it and it's connected to a LED display.</li>
  <li>There are a few executables on the Pi to make this LED display works.</li>
  <li>I want my php script to fetch datas from the web with some APIs and display the result on the LED.</li>
  </ul>
  
  <p>So, the display works fine. I have installed a C-based program in the the /var/www/ and here is an example</p>
  
  <p>on <code>/var/www/</code>: <code>sudo ./text-example -f fonts/5x8.bdf -r 16</code></p>
  
  <p>(-f for the font used, -r for the number of rows of my LED)</p>
  
  <p>When you execute this, you can write some text in the shell and it will display it on the LED.</p>
  
  <p>So I made a simple <code>test.php</code> script with the following: <code>$res = shell_exec('sudo ./test-example -f fonts/5x8.bdf -r 16');</code> and it works too. I can enter messages in the <code>STDIN</code>.</p>
  
  <p>A little further, now I need to enter the text dynamically so I did a <code>proc_open()</code> in a <code>proc.php</code>:</p>
  
  <pre><code>&lt;?php
  $desc = array(0=&gt;array("pipe", "r"), 1=&gt;array("pipe", "w"));
  $cwd = '/var/www/';
  $process = proc_open('php test.php', $desc, $pipes, $cwd, NULL);
  
  if (is_resource($process)) {
     fwrite($pipes[0], 'hello');
     fclose($pipes[0]);
  
  }
  ?&gt;
  </code></pre>
  
  <p>So, now I run in the shell: <code>php proc.php</code>. As soon as I define a <code>$desc</code> with pipe, the programm will execute, and then stop. The LED display is not displaying anything. If I remove the <code>$desc</code> variable and remove the pipes things (<code>fwrite</code>, <code>fclose</code>), I can enter text in the shell and it will execute properly as if it was <code>test.php</code>. I don't understand why it won't let me <code>STDIN</code> with <code>fwrite</code> and why the php is interrupted with theses pipes.</p>