S
S
Sergey Belyakov2019-09-17 14:32:04
Yii
Sergey Belyakov, 2019-09-17 14:32:04

How to check availability of remote computer in yii2 local network?

Good afternoon! I have a function that connects to a remote machine on the local network via ssh and executes the command I need. And she works. But if the machine is not available (turned off or something else), the application fails.
Here is the function

public function actionCommand($host,$username,$password){
        $console = "usbsrv -list";
        $yii_ssh = new Yii2ssh();
        $auth['username'] = $username; // логин
        $auth['password'] = $password; // пароль
        $session = $yii_ssh->connect($host, $auth); // подключаемся


        if($session){
            $lin = $yii_ssh->run_ssh($console);
            $line = explode("\n", $lin);
        }
        else{
            $line = false;
//            $line = 'Сервер не доступен, попробуйте позже';
        }
        return $line;
    }

And here is the error:
PHP Warning – yii\base\ErrorException
fclose() expects parameter 1 to be resource, boolean given
↵
Caused by: yii\base\ErrorException

in C:\OSPanel\domains\localhost\rutoken.loc\vendor\phpseclib\phpseclib\phpseclib\Net\SSH2.php at line 1152

5d80c407d6386002630022.png
The application is written in yii2, I use the behnampro\yii2ssh\Yii2ssh library in it . It allows you to execute commands via ssh on remote machines. How to fix the error?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question