/**
* Method to fork the process.
*
* @return integer The child process id to the parent process, zero to the child process.
*
* @since 1.7.0
* @throws \RuntimeException
*/
protected function fork()
{
// Attempt to fork the process.
$pid = $this->pcntlFork();
// If the fork failed, throw an exception.
if ($pid === -1) {
throw new \RuntimeException('The process could not be forked.');
} elseif ($pid === 0) {
$this->processId = (int) posix_getpid();
} else {
// Log the fork.
Log::add('Process forked ' . $pid, Log::DEBUG);
}
// Trigger the onFork event.
$this->postFork();
return $pid;
}