php - 通过php我如何关闭由php ssh2_connect创建的事件ssh连接?

标签 php ssh

我使用以下代码创建了ssh连接。

    $connection = ssh2_connect($masterIp, 22);

    // authenticating the remote server connection with credentials
    ssh2_auth_password($connection, $user, $password);

    // secure ftp connection to create directory if not exist
    $sftp = ssh2_sftp($connection);

完成操作后,我需要关闭$ connection,$ sftp。
如何安全地关闭连接。我可以使用unset()函数吗?

最佳答案

是的,未设置就足够了。

在PHP中,当资源超出范围或未设置时,它们将自动关闭(无论如何,它们都应该是关闭的,除非扩展破坏了标准的PHP模型)。

(好吧,它只会被车库收集,并在所有对资源的引用都被销毁时关闭)

关于php - 通过php我如何关闭由php ssh2_connect创建的事件ssh连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10927553/

相关文章:

php - 自定义组件后端中的 Joomla 3.0 MVC 文件上传

php - 在 Laravel 中一次更新多列值

batch-file - WinSCP "Too many parameters for command ' 打开'。”错误

git - 无法推送到远程 repo - "Please make sure you have the correct access rights and the repository exists."

mysql - 无法通过 SSH 连接到 MySQL 服务器(由 strato 托管)

vb.net - 上传文件到服务器时WinSCP错误 "No such file"

linux - 无法连接到我的 aws ec2 实例

php - 处理 PHP 脚本中的 If-modified-since header

php - 我可以使用同一个表中的 2 个外键构建 MySQL 数据库表吗?

php - 单元测试创​​建对象的方法