public static function become_daemon(callable $call = null) : int        // do not use this unless you know what you are doing
    {
        if (!\extension_loaded('pcntl')) {
            print 'You must have the PCNTL extencion installed. See Carbon PHP for documentation.' and die;
        }

        if ($pid = pcntl_fork()) {  // Parent
            if (\is_callable($call)) {
                return 1;
            }
            exit;
        }
        if ($pid < 0) {
            throw new \RuntimeException('Failed to fork');
        }

        \define('FORK', TRUE);

        /* child becomes our daemon */
        posix_setsid();

        chdir('/');   // What does this do ?

        umask(0);        // Give access to nothing

        register_shutdown_function(function () {
            session_abort();
            posix_kill(posix_getpid(), SIGHUP);
            exit(1);
        });

        if (\is_callable($call)) {
            $call();
            exit(1);
        }

        return posix_getpid();
    }
public static function become_daemon(callable $call = null) : int        // do not use this unless you know what you are doing
    {
        if (!\extension_loaded('pcntl')) {
            print 'You must have the PCNTL extencion installed. See Carbon PHP for documentation.' and die;
        }

        if ($pid = pcntl_fork()) {  // Parent
            if (\is_callable($call)) {
                return 1;
            }
            exit;
        }
        if ($pid < 0) {
            throw new \RuntimeException('Failed to fork');
        }

        \define('FORK', TRUE);

        /* child becomes our daemon */
        posix_setsid();

        chdir('/');   // What does this do ?

        umask(0);        // Give access to nothing

        register_shutdown_function(function () {
            session_abort();
            posix_kill(posix_getpid(), SIGHUP);
            exit(1);
        });

        if (\is_callable($call)) {
            $call();
            exit(1);
        }

        return posix_getpid();
    }
public static function become_daemon ( callable $ call = null ) : int // do not use this unless you know what you are doing { if ( ! \ extension_loaded ( 'pcntl' ) ) { print 'You must have the PCNTL extencion installed. See Carbon PHP for documentation.' and die ; } if ( $ pid = pcntl_fork ( ) ) { // Parent if ( \ is_callable ( $ call ) ) { return 1 ; } exit ; } if ( $ pid < 0 ) { throw new \ RuntimeException ( 'Failed to fork' ) ; } \ define ( 'FORK' , TRUE ) ; /* child becomes our daemon */ posix_setsid ( ) ; chdir ( '/' ) ; // What does this do ? umask ( 0 ) ; // Give access to nothing register_shutdown_function ( function ( ) { session_abort ( ) ; posix_kill ( posix_getpid ( ) , SIGHUP ) ; exit ( 1 ) ; } ) ; if ( \ is_callable ( $ call ) ) { $ call ( ) ; exit ( 1 ) ; } return posix_getpid ( ) ; }
If a callable function is passes the interpreter will attempt to
fork using the pncl library and then execute the desired closure.
If no arguments are passed than the current execution environment
will become "Demonized". All masks will be set to 0 and the new
working environment will be the root dir. This can be exceptionally
dangerous and should only be used if your absolutely
sure you know whats going on.
@param callable|null $call
@return int
@throws \Exception
If a callable function is passes the interpreter will attempt to fork using the pncl library and then execute the desired closure . If no arguments are passed than the current execution environment will become Demonized . All masks will be set to 0 and the new working environment will be the root dir . This can be exceptionally dangerous and should only be used if your absolutely sure you know whats going on .