Dan*_*ele 6 php ssh sftp segmentation-fault amazon-web-services
我有一个在AWS上运行的php系统和一个使用shh2和sftp在外部服务器上上传xlsx文件的类.此代码工作得很好,直到AWS包的最后升级的openssh-客户-6.6.1p1-31.62和OpenSSH的服务器,6.6.1p1-31.62这个时候,我有一个段错误时的fopen.Fopen在外部服务器上创建一个文件.这里的代码:
$stream = @fopen("ssh2.sftp://$this->sftp$remote_file", 'w');
Run Code Online (Sandbox Code Playgroud)
然后我使用$ stream来编写内容,但代码停止在fopen上因为一个段错误.我没有发现任何关于这个问题,我认为问题是opnessh的新升级,因为php代码没有改变.任何的想法?
Chr*_*ian 18
在StackOverflow上找到答案:https://stackoverflow.com/a/40972584/2520795
自从这次PHP更新以来,你必须用你的主机部分(结果ssh2_sftp())包围intval():
$handle = opendir("ssh2.sftp://".intval($sftp)."/path/to/directory");
Run Code Online (Sandbox Code Playgroud)
在我的情况下,有一个fopen而不是一个opendir,但解决方案是相同的.
小智 6
您可能会遇到“段错误”的问题,即使intval($sftp)如果您要关闭与连接解决方案ssh2_disconnect()。正确的解决方案是在关闭 SSH2 连接之前关闭 SFTP 连接unset($sftp)或$sftp = null。这是我读取远程文件的完整示例:
if (!$ssh2_connection = ssh2_connect($host, $port)) {
die("Failed to connect\n");
}
if (!ssh2_auth_password($ssh2_connection, $username, $password)) {
die("Failed to login\n");
}
if (!$sftp_connection = ssh2_sftp($ssh2_connection)) {
die("Failed to open SFTP session\n");
}
if (!$fh = fopen("ssh2.sftp://".intval($sftp_connection).$path, 'r')) {
die("Failed to open file\n");
}
while (($s = fgets($fh)) !== false) {
echo $s;
}
fclose($fh);
unset($sftp_connection);
if (!ssh2_disconnect($ssh2_connection)) {
die("Failed to disconnect\n");
}
Run Code Online (Sandbox Code Playgroud)
PS 另外,您可能会看到类似的内容,而不是“分段错误”:
php: channel.c:2570: _libssh2_channel_free: 断言“会话”失败。
中止
我的解决方案解决了它。
| 归档时间: |
|
| 查看次数: |
4093 次 |
| 最近记录: |