php-我仍然无法处理SSH连接错误

我正在尝试处理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,而不是重定向.

enter image description here

我想要的是,如果通过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');
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...