我试图处理RunTimeException通过SSH连接到VPS。我无法处理SSH连接错误
下面是通过SSH连接VPS的代码。
$server_ip = Input::get('server_ip');
$password = Input::get('password');
$validator = Validator::make(
['server_ip' => $server_ip],
['server_ip' => 'ip|required|unique:servers'],
['password' => $password],
['password' => 'required|confirmed']
);
if(!$validator->fails())
{
Config::set('remote.connections.production.host',$server_ip);
Config::set('remote.connections.production.username','root');
Config::set('remote.connections.production.password',$password);
Config::set('remote.connections.production.root','/');
$command = 'mysql --version';
$connection_status = SSH::run($command, function($line)
{
$this->output = $line.PHP_EOL;
});
if(!$connection_status)
return $this->output;
else
return view('dashboard.add_server');
}
else
return "Validation failed...";
这是写在Laravel。万一,如果我的SSH连接出错,它应该重定向到查看名为add_server
。但是,我得到异常而不是重定向。这里是我每次都会遇到的错误,而不是重定向。
我要的是,如果有一些错误的连接通过SSH到VPS,它应该重定向我查看名为add_server
让我知道什么是错的代码。
我试过这段代码。不过,我得到了同样的异常,但没有重定向。 –