title: PHP proc_open run multiple processes at same time
body: <p>I'm trying to run a Cake PHP 2 console command in my project through a shell I've written called <code>queue_manager</code> and a task called <code>schedule_run</code>.</p>
  <p>I need to be able to run my shell's <code>process</code> command 3 times side by side in different processes so am trying to use the <code>proc_open</code> command but when I run it and run <code>ps</code> in my terminal I only get one process shown.</p>
  <p>Currently I have a single cronjob that runs my queue_manager schedule_run<code>command every minute, and it's this that then loops over a variable 3 times and attempts to spawn multiple processes to run my</code>process<code>command, but my</code>for<code>loop appears to be waiting for the first</code>proc_open<code>command to finish before moving to the next thus there only being one</code>ps` output in my terminal.</p>
  <p>Why isn't this running multiple execs side by side:</p>
  <pre class="lang-php prettyprint-override"><code>/**
    * Main execute task
    */
    public function execute() {
        $maxWorkers = 3;
  
        for ($workers = 0; $workers &lt; $maxWorkers; $workers++) {
            $descriptorspec = array(
               0 =&gt; array(&quot;pipe&quot;, &quot;r&quot;),  // stdin is a pipe that the child will read from
               1 =&gt; array(&quot;pipe&quot;, &quot;w&quot;),  // stdout is a pipe that the child will write to
               2 =&gt; array(&quot;file&quot;, APP . '/output.txt', &quot;a&quot;) // stderr is a file to write to
            );
  
            $cwd = '/tmp';
            $env = array('some_option' =&gt; 'aeiou');
  
            $process = proc_open('cd ' . APP . &quot; &amp;&amp; Console/cake queue_manager process&quot;, $descriptorspec, $pipes, $cwd, $env);
            fwrite($pipes[0], '&lt;?php print_r($_ENV); ?&gt;');
            fclose($pipes[0]);
  
            echo stream_get_contents($pipes[1]);
            fclose($pipes[1]);
  
            $return_value = proc_close($process);
            $this-&gt;out($return_value);
        }
    }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/NZ8JX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NZ8JX.png" alt="enter image description here" /></a></p>