title: PHP pcntl Variable Scope
body: <p>I want to be able to modify array elements that are in the parent pid. Here is some example code:</p>
  
  <pre><code>$arrayContainer = array(
      array(
            "id" =&gt; 1,
            "name" =&gt; "Lenny"
      ),
      array(
            "id" =&gt; 2,
            "name" =&gt; "Dudley"
      ),
      array(
            "id" =&gt; 3,
            "name" =&gt; "Simon"
      ),
  );
  
  foreach ($arrayContainer as $key =&gt; $element) {
      $pid = pcntl_fork();
      if($pid == -1) {
          // Something went wrong (handle errors here)
          die("Could not fork!");
      } elseif($pid == 0) {
          $arrayContainer[$key]['size'] = 123;
          $arrayContainer[$key]['fileName'] = 'somefile.txt';
          // The child dies after a short while, becoming a zombie
          exit();  
      } else {
          // This part is only executed in the parent
      }
  }
  </code></pre>
  
  <p>So when this script ends the two elements i wrote in the child process are not there at the end of the foreach loop. I can't modify the array that is in the parent pid from the child. I understand why but can't think of a nice solution that will allow me to. Can you suggest anything? Globals or something?</p>