Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

pcntl_fork

Description

The pcntl_fork of PCNTL for PHP forks the currently running process.

Syntax

pcntl_fork(): int

Return

On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution.

On failure, a -1 will be returned in the parent's context, no child process will be created, and a PHP error is raised.

Examples

1 · void

<?

$return = pcntl_fork();

echo $return;

?>

2 · parent child

<?

$return = pcntl_fork();

if($return == -1)
{
    die("pcntl_fork");
}
else if($return)
{
    echo "parent: $return";

    pcntl_wait($status);//protect against zombie children
}
else
{
    echo "child: $return";
}

?>
child: 0
HomeMenu