title: Why stream_set_blocking() and stream_select() giving error?
body: <p>I am new to php and i am trying to write a php script to compile and execute a C source code . Here is my source code :  </p>
  
  <pre><code>      &lt;?php
          $cmd = "gcc -g test.c -o test";
  
          $descriptors = array(
              2 =&gt; array("pipe","w+")
          );
  
          $process = proc_open($cmd,$descriptors,$pipes);
  
          stream_set_blocking($pipes[2],0);
  
          if($error = stream_get_contents($pipes[2]))
          {
              die($error);
          }
  
          fclose($pipes[2]);
          proc_close($process);
  
          $cmd = "./test";
  
          $descriptors = array(
              0 =&gt; array("file","input.txt","r"),
              1 =&gt; array("file","output.txt","w"),
              2 =&gt; array("pipe","w+")
          );
  
          $process = proc_open($cmd,$descriptors,$pipes);
  
          stream_set_blocking($pipes[2],0);
  
          if($error = stream_get_contents($pipes[2]))
          {
              die($error);
          }
          else
          {
          /*line -&gt; 38 */ stream_set_blocking($pipes[1],1);
  
          /*line -&gt; 40 */ $read = array($pipes[1],$pipes[2]);
              $write = NULL;
              $except = NULL;
              $tv_sec = 0;
              $tv_usec = 1000;
  
     /*line -&gt; 46*/       if(false === ($rs = stream_select($read,$write,$except,$tv_sec,$tv_usec)) )
              {
                  die("Error in stream_reader");
              }
  
     /*line -&gt; 51*/       fclose($pipes[0]);
     /*line -&gt; 52*/       fclose($pipes[1]);
              fclose($pipes[2]);
  
              proc_close($process);
          }
  
          $out = @fopen("output.txt","r");
          $test = @fopen("test.txt","r");
  
          while((($out_buffer = fgets($out)) !== false) &amp;&amp; (($test_buffer = fgets($test)) !== false))
          {
              if($out_buffer !== $test_buffer)
              {
                  die("Error in output.");
              }
          }
  
          if(!feof($out) || !feof($test))
          {
              die("Error in output.");
          }
  
  
      ?&gt;
  </code></pre>
  
  <p>Here is my error :  </p>
  
  <pre><code>Undefined offset: 1 in file.php on line 38  
  stream_set_blocking() expects parameter 1 to be resource, null given  in file.php on line 38  
  Undefined offset: 1 in file.php on line 40  
  stream_select(): supplied argument is not a valid stream resource in file.php on line 46  
  stream_select(): supplied argument is not a valid stream resource in file.php on line 46  
  stream_select(): supplied argument is not a valid stream resource in file.php on line 46  
  Undefined offset: 0 in file.php on line 51  
  fclose() expects parameter 1 to be resource, null given in file.php on line 51  
  Undefined offset: 1 in file.php on line 52  
  fclose() expects parameter 1 to be resource, null given in file.php on line 52 
  </code></pre>
  
  <p>Please anybody tell me where i am wrong , can't we not use stream_set_blocking() when stream is file?
  Thank you!</p>