我正在尝试处理RunTimeException以通过SSH与VPS连接.
这是通过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的视图.但是,我得到了异常而不是重定向.这是我每次都收到的Errror,而不是重定向.
我想要的是,如果通过SSH与VPS有一些错误连接,它应该将我重定向到名为add_server的视图
让我知道代码有什么问题.
解决方法:
try
{
$connection_status = SSH::run($command, function($line)
{
$this->output = $line.PHP_EOL;
});
if(!$connection_status)
return $this->output;
}
catch(\RunTimeException $e)
{
return view('dashboard.add_server');
}