php 与 ssh2_connect() 断开连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5820089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:35:40  来源:igfitidea点击:

Disconnect from ssh2_connect()

phpsshdisconnect

提问by Incognito

I've connected over ssh2 using ssh2_connectto a server, but I don't see any method in the manpagesfor how I should end the connection.

我已经通过 ssh2 连接ssh2_connect到服务器,但在联机帮助页中没有看到任何关于如何结束连接的方法。

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...

我可以使用fclose吗?这听起来不对...

回答by Treffynnon

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

只是unset($connection)您的连接变量或ssh2_exec($connection, 'exit');可能会这样做。

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

为了更有说服力,您可能会执行以下操作!

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

回答by Incognito

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.

如果您使用的是phpseclib(一种纯 PHP SSH 实现),则可以执行$ssh->disconnect(). phpseclib 的析构函数调用它,但您也可以手动调用它。

回答by Flask

ssh2_exec('logout')should kill your session…

ssh2_exec('logout')应该杀死你的会话......