public static function safe(callable $closure = null) : int
    {
        if (!\extension_loaded('pcntl')) {
            if ($closure !== null) {
                $closure();
            }
            return 0;
        }
        if ($pid = pcntl_fork()) {    // return child id for parent and 0 for child
            return $pid;             // Parent
        }
        if ($pid < 0) {
            throw new \RuntimeException('Failed to fork');
        }
        \define('FORK', true);
        // Database::resetConnection();
        // fclose(STDIN); -- unset
        register_shutdown_function(function () {
            session_abort();
            posix_kill(posix_getpid(), SIGHUP);
            exit(1);
        });

        if ($closure !== null) {
            $closure();
        }
        exit;
    }
public static function safe(callable $closure = null) : int
    {
        if (!\extension_loaded('pcntl')) {
            if ($closure !== null) {
                $closure();
            }
            return 0;
        }
        if ($pid = pcntl_fork()) {    // return child id for parent and 0 for child
            return $pid;             // Parent
        }
        if ($pid < 0) {
            throw new \RuntimeException('Failed to fork');
        }
        \define('FORK', true);
        // Database::resetConnection();
        // fclose(STDIN); -- unset
        register_shutdown_function(function () {
            session_abort();
            posix_kill(posix_getpid(), SIGHUP);
            exit(1);
        });

        if ($closure !== null) {
            $closure();
        }
        exit;
    }
public static function safe ( callable $ closure = null ) : int { if ( ! \ extension_loaded ( 'pcntl' ) ) { if ( $ closure !== null ) { $ closure ( ) ; } return 0 ; } if ( $ pid = pcntl_fork ( ) ) { // return child id for parent and 0 for child return $ pid ; // Parent } if ( $ pid < 0 ) { throw new \ RuntimeException ( 'Failed to fork' ) ; } \ define ( 'FORK' , true ) ; // Database::resetConnection(); // fclose(STDIN); -- unset register_shutdown_function ( function ( ) { session_abort ( ) ; posix_kill ( posix_getpid ( ) , SIGHUP ) ; exit ( 1 ) ; } ) ; if ( $ closure !== null ) { $ closure ( ) ; } exit ; }
This will safely execute a passed closure if the pncl library in not
found in the environment. This should only be used when the callable
function does not access or modify the database or session. Carbon uses
this when realtime communication using named pipe is requested. It only
speeds up execution, however it is not required and will never throw an
error.
@param callable|null $closure
@return int
@throws \Exception
This will safely execute a passed closure if the pncl library in not found in the environment . This should only be used when the callable function does not access or modify the database or session . Carbon uses this when realtime communication using named pipe is requested . It only speeds up execution however it is not required and will never throw an error .