I am working on one project that requires me to execute some commands on remote server. I am using Laravel 5.5 with package name "laravelcollective/remote" that uses SSH2 to connect with the remote server.
However, I am facing some really weird issues with some servers. I get the following error message on some of the servers.
production.ERROR: Connection closed prematurely {"exception":"[object] (ErrorException(code: 0): Connection closed prematurely at /home/username/application_name/public_html/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:3821, RuntimeException(code: 0): Unable to connect to remote server. at /home/username/application_name/public_html/vendor/laravelcollective/remote/src/Connection.php:143)
I am using try-catch
block to catch exceptions but I am unable to catch this exception. All other Exceptions like connection timed out
are being caught by the try-catch block except this one.
I am using try catch block like this:
try {
$commands = array('sudo apt-get update','sudo apt-get upgrade -y');
SSH::run($commands);
} catch (\Exception $e){
report($e);
}
But the try-catch block stops working with this connection closed prematurely
error. I don't know if I am missing something or there is some bug with the library, has anyone faced the same issue before? How can I catch this error the right way?