Dutch PHP Conference 2021 - Call for Papers


(PECL ssh2 >= 1.0)

ssh2_disconnectFerme une connexion à un serveur SSH distant


ssh2_disconnect ( resource $session ) : bool

Ferme une connexion à un serveur SSH distant.

Liste de paramètres


Un identifiant de lien de connexion SSH, obtenu depuis un appel à ssh2_connect().

Valeurs de retour

Cette fonction retourne true en cas de succès ou false si une erreur survient.

Voir aussi

add a note add a note

User Contributed Notes 2 notes

2 years ago
ssh2_disconnect(...) requires at least PHP 7 (as it requires PECL ssh2 >= 1.0, which the PECL documentation on https://pecl.php.net/package/ssh2 states: "ssh2 1.0 and above is PHP 7 only").

For PHP 5.x similar functionality, try setting the ssh2_connect session variable to null, or unsetting it completely - this should allow PHP's garbage collection close the connection.


$session=ssh2_connect(...); // open connection
// code here to use connection
$session = null; unset($session); // close connection
Anton Farber
4 months ago
This function worked fine as long as I didn't use any ssh2_sftp* stuff. As soon as I did, the connection (from my webserver to my browser) was closed without any warning/error in any of the logfiles. So, this won't work

// ssh2_connect and ssh2_auth etc...
$sftp = ssh2_sftp($connection);
ssh2_disconnect(); // Causes the connection to be reset

while this works

// ssh2_connect and ssh2_auth etc...
$sftp = ssh2_sftp($connection);
$connection = null; unset($connection);
To Top