phpseclib挂起webserver直到所有命令都运行完毕

I'm trying to send some commands to a Debian server and these commands take up to 30 seconds to complete which is fine but whenever someone on my webserver clicks the button (which tells php to run the commands with phpseclib) the entire website just freezes (it just keeps loading and loading if you try accessing it) until either all the commands have been ran or until timeout.

Code

    $this->_ssh = new Net_SSH2($this->_ip);

    if(!$this->_ssh->login($this->_username, $this->_password))
        die('Could not connect with SSH: Login failed!');


        $cd_to_subdir_command = 'cd ' . $this->_path . "
";
        $rmdir_command = '[ -d ' . $this->_screen . ' ] || rm -rf ' . $this->_screen;
        $mkdir_command = 'mkdir ' . $this->_screen;
        $extract_command = 'tar -xzf hlds_no_amxx.tar.gz -C ' . $this->_screen . "
";
        $chmod_command = 'chmod -R 777 ' . $this->_screen . "
";


        $this->_ssh->read(':~$');
        $this->_ssh->write($cd_to_subdir_command . "
");
        $this->_ssh->write($rmdir_command . "
");
        $this->_ssh->write($mkdir_command . "
");
        $this->_ssh->write($extract_command . "
");
        $this->_ssh->write($chmod_command . "
");
        $this->_ssh->setTimeout(30); // 30 seconds timeout to give it time to extract because the file is really big

        $this->_ssh->read();

I need the webserver not to do this because obviously 30 second loading times are a pain and not to mention only 1 user would be able to do stuff at a time.

If you don't need the result immediatly, I'd put the code in an external script/php file and only run

$this->ssh->exec('nohup php /full/path/file.php');

You can remove the timeout at the end and just let the file execute whatever it has to do. nohup puts it in the background.

I was looking in the wrong direction. The problem here is not the server hanging or anything like that when sending the SSH commands.

I'm using ajax to call the function that has the SSH code in it. In this case the SSH code is irrelevant. The webserver can only handle the one ajax request from the client and because of that the client won't be able to use the website until the ajax request has returned success or error.

TLDR: This isn't a problem that needs solving. Its ajax thats the culprit here and not ssh or the debian server.