Disconnect from ssh2_connect()

╄→гoц情女王★ 提交于 2019-12-12 08:18:56

问题


I've connected over ssh2 using ssh2_connect to a server, but I don't see any method in the manpages for how I should end the connection.

I'm not exactly a fan of waiting for a script to end before I disconnect.

Can I use fclose? That doesn't sound right...


回答1:


Just unset($connection) your connection variable or ssh2_exec($connection, 'exit'); might do it.

You could probably do the following in order to be even more convincing!

ssh2_exec($connection, 'exit');
unset($connection);



回答2:


If you were using phpseclib, a pure PHP SSH implementation, you could do $ssh->disconnect(). phpseclib's destructor calls it but you could call it manually as well.




回答3:


ssh2_exec('logout') should kill your session…



来源:https://stackoverflow.com/questions/5820089/disconnect-from-ssh2-connect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!