On 9/29/12 1:48 PM, Wade Shearer wrote:
> I have a foreach in which I use pcntl_fork to fork off an independent
> process. This is so that thinks can be executed non-linearly. I want
> to define a constant immediately after the fork. My script fails
> however stating it cannot define the constant because it is already
> defined (the second loop in the foreach I assume). Is there a way for
> the fork to maintain a unique global namespace?

I believe that your code may be buggy.  I tried the following program, 
and it completed successfully:

#!/usr/bin/php
<?

for ($i = 0; $i < 5; $i++) {
        echo "Forking #$i...\n";
        $pid = pcntl_fork();
        if (!$pid) {
                define("TEST_CONSTANT", 1);
                echo "Successfully forked #$i!\n";
                exit();
        }
        sleep(1);
}

echo "Completed!\n";

?>


This leads me to believe that in your forked code, you may be continuing 
the loop, or something equally problematic.  Once the process forks, 
there should be no interaction between the child and the parent, so any 
constants defined in the child would not affect the parent.

Steve

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to