微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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');
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐