Back to DaemonApplication class

Method fork

protected int
fork
()
Method to fork the process.
Returns
  • int The child process id to the parent process, zero to the child process.
Since
  • 1.7.0
-
  • \RuntimeException

Method fork - Source code

/**
 * 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;
}