pcntl fork and standart output

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ebl
Forum Newbie
Posts: 1
Joined: Mon Sep 20, 2010 4:24 am

pcntl fork and standart output

Post by ebl »

i run this code on lighttp server

Code: Select all

	$pid = pcntl_fork();
	if ($pid == -1) {
	     die('could not fork');
	} else if ($pid) {
		pcntl_wait($status,WNOHANG);
		$fp = fopen("tmp","a");
	 	fwrite($fp,"parent");
	 	fclose($fp);
		echo " back to parent ";
	 } else {
	 	$fp = fopen("tmp","a");
	 	fwrite($fp,"sun ");
	 	fclose($fp);
		echo " sun ";
		
	}

and i get the following output:
on the screen i get only "sun"
and on the tmp file i get "sun parent"

how can i get the parent to continue output?

thanks
Post Reply