public static function fork()
    {
        $pid = pcntl_fork();
        if ($pid === -1) {
            throw new \RuntimeException('Failed to fork PHP process');
        } elseif ($pid > 0) {
            // This is the parent process. If the child process succeeds, this
            // receives SIGCHLD. If it fails, this receives SIGTERM.
            declare (ticks = 1);
            pcntl_signal(SIGCHLD, function () {
                exit;
            });
            pcntl_signal(SIGTERM, function () {
                exit(1);
            });

            // Wait a reasonable amount of time for the child processes to
            // finish.
            sleep(60);
            throw new \RuntimeException('Timeout in parent process');
        } elseif (posix_setsid() === -1) {
            throw new \RuntimeException('Child process failed to become session leader');
        }
    }
public static function fork()
    {
        $pid = pcntl_fork();
        if ($pid === -1) {
            throw new \RuntimeException('Failed to fork PHP process');
        } elseif ($pid > 0) {
            // This is the parent process. If the child process succeeds, this
            // receives SIGCHLD. If it fails, this receives SIGTERM.
            declare (ticks = 1);
            pcntl_signal(SIGCHLD, function () {
                exit;
            });
            pcntl_signal(SIGTERM, function () {
                exit(1);
            });

            // Wait a reasonable amount of time for the child processes to
            // finish.
            sleep(60);
            throw new \RuntimeException('Timeout in parent process');
        } elseif (posix_setsid() === -1) {
            throw new \RuntimeException('Child process failed to become session leader');
        }
    }
public static function fork ( ) { $ pid = pcntl_fork ( ) ; if ( $ pid === - 1 ) { throw new \ RuntimeException ( 'Failed to fork PHP process' ) ; } elseif ( $ pid > 0 ) { // This is the parent process. If the child process succeeds, this // receives SIGCHLD. If it fails, this receives SIGTERM. declare ( ticks = 1 ) ; pcntl_signal ( SIGCHLD , function ( ) { exit ; } ) ; pcntl_signal ( SIGTERM , function ( ) { exit ( 1 ) ; } ) ; // Wait a reasonable amount of time for the child processes to // finish. sleep ( 60 ) ; throw new \ RuntimeException ( 'Timeout in parent process' ) ; } elseif ( posix_setsid ( ) === - 1 ) { throw new \ RuntimeException ( 'Child process failed to become session leader' ) ; } }
Fork the current PHP process.

Code run after this method is run in a child process. The parent process
merely waits for a SIGCHLD (successful) or SIGTERM (error) signal from
the child.

This depends on the PCNTL extension.
Fork the current PHP process .