Search code examples
phpsshsftp

check connection with ssh2 functions in PHP


I need to check the connection with the function http://php.net/manual/en/function.ssh2-connect.php

But if I made a check like this

$connection = ssh2_connect('myserver.com', 22);         
if (!$connection){
    echo 'no connection';
}else{
    echo 'connection ok';
}

I never get into the line " echo 'no connection'; "

Can you explain me why? And how to make a check like that?

Thanks in advance!


Solution

  • It depends on your server. Try to connect to some non-existing one and see what happens.

    If you need to check only connection, then you can use something like http://php.net/manual/en/function.fsockopen.php also