All pastes #415891 Raw Edit

Cobi

public php v1 · immutable
#415891 ·published 2007-03-29 22:33 UTC
rendered paste body
<?PHP	declare(ticks=1);	function handleforks ($signo) {		global $fifos;		while (($pid = pcntl_waitpid(-1, $status, WNOHANG)) > 0) {			$fifo = $fifos[$pid]['fifo'];				$thefifo = $fifos[$pid]['fd'];			$x = '';			while (!feof($thefifo)) {				$x .= fread($thefifo,4096);			}			print_r(unserialize($x));			unset($x);			fclose($thefifo);			unset($thefifo);			unlink($fifo);			unset($fifo);		}	}	pcntl_signal(SIGCHLD, "handleforks");//	pcntl_signal(SIGUSR1, "handlefifos");	$fifo = tempnam('/tmp/','phpfork');	unlink($fifo);	posix_mkfifo($fifo,0600);	$pid = pcntl_fork();	if ($pid == -1) {		die('Uh-oh...');	} elseif ($pid) {		/* The parent . . . Do stuffs. */		$fifos[$pid]['fifo'] = $fifo;		$fifos[$pid]['fd'] = fopen($fifos[$pid]['fifo'],'r');		while (1) {			sleep(5);		}	} else {		$xyz123 = 'Testing!';		$thepid = posix_getpid();		echo 'fork running...';//		posix_kill(posix_getppid(),SIGUSR1);		$thefifo = fopen($fifo,'a');		echo 'fifo opened';		fwrite($thefifo,serialize(get_defined_vars()));		echo ' fifo wrote';		fclose($thefifo);		echo 'fork died.';		die();	}?>