[UPHPU] unable to define constant after forking process

Steve Meyers steve-uphpu at spamwiz.com
Sat Sep 29 22:27:58 MDT 2012

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:


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

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.


More information about the UPHPU mailing list