Answer the question
In order to leave comments, you need to log in
How to check the connection in a machine in php 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;
}
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
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question