Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php sftp seg故障_Php_Sftp_Readdir - Fatal编程技术网

php sftp seg故障

php sftp seg故障,php,sftp,readdir,Php,Sftp,Readdir,如果下一个代码给我seg错误,我需要做什么 $handle = opendir("ssh2.sftp://$sftp".'/usr/bin/'); $file = readdir($handle); closedir($handle); $sftp在哪里 $this->_connection = ssh2_connect($this->_server, 22); if($this->_authType==ExportInterface:

如果下一个代码给我seg错误,我需要做什么

    $handle = opendir("ssh2.sftp://$sftp".'/usr/bin/');
    $file = readdir($handle);
    closedir($handle);
$sftp在哪里

    $this->_connection = ssh2_connect($this->_server, 22);
    if($this->_authType==ExportInterface::CONN_AUTH_KEY) {
        ssh2_auth_pubkey_file($this->_connection,$this->_user,$this->_key,$this->_privateKey);
    } else {
        ssh2_auth_password($this->_connection,$this->_user,$this->_password);
    }
    $sftp = ssh2_sftp($this->_connection);
连接工作良好。segfault是我唯一使用readdir函数的时候

seg(mentation)故障是php或SSH/SFTP扩展中的内部错误。你应该反对有问题的延期

别忘了写一封信。由于这可能仅在ssh客户端和服务器的特定组合中才能重现,因此您应该首先在全新的VM中重现错误,并记录您执行的每个步骤,如下所示:

  • 在虚拟机中安装Ubuntu 11.04 amd64
  • 使用
    $sudo apt get安装ssh安装ssh
  • 使用…配置ssh
  • 使用
    $sudo apt get Install php5 cli安装php
  • 将脚本[链接到此处]复制到VM
  • 键入
    php ssh segfault.php
    并接收一个segfault

  • 我有同样的问题,我解决了它升级到版本0.11.3的ssh2 pecl包

    sudo pecl install ssh2 channel://pecl.php.net/ssh2-0.11.3
    
    在遇到一些问题后,它对我起了作用


    关于

    我也有类似的问题,不过还有一些额外的因素。我将从解决方案开始:使用绝对路径,而不是相对路径。避免使用
    ~

    至于我的发现。以这个脚本为例:

    #!/usr/bin/php
    <?php
    
    $ssh = ssh2_connect('hostname.example.com');
    $res = ssh2_auth_pubkey_file($ssh, 'user', '~/.ssh/various-keys/special-key_2015.pub', '~/.ssh/various-keys/special-key_2015');
    unset($res); unset($ssh);
    
    $ssh = ssh2_connect('hostname.example.com');
    $res = ssh2_auth_pubkey_file($ssh, 'user', '~/.ssh/various-keys/special-key_2015.pub', '~/.ssh/various-keys/special-key_2015');
    

    我希望这对其他人有所帮助…

    我回答这个老问题是因为谷歌搜索排名很高。我遇到了同样的分割错误,而真正的解决方案不在这里

    事实证明,自PHP5.6以来,函数
    ssh2\u sftp
    的行为发生了变化,现在返回一个资源,该资源不允许作为字符串连接以形成文件系统路径

    因此,一旦您返回了
    ssh2\u sftp
    ,您必须首先通过
    intval
    来构建远程文件路径:

    $sftp = ssh2_sftp($this->_connection);
    $handle = opendir('ssh2.sftp://' . intval($sftp) . '/usr/bin/');
    $file = readdir($handle);
    closedir($handle);
    

    不客气。

    不适用于OP的情况,但是如果您未能在opendir创建的句柄上显式调用closedir,那么在脚本末尾的PHP内部清理过程中,您也会得到一个segfault。

    上面的一个答案建议您需要将资源强制转换为int
    intval($sftp)
    以避免segfault

    虽然我相信过去是这样,但现在似乎已经发生了逆转,至少在PHP7.1.9上是这样,现在强制转换为int会导致segfault,至少在
    文件内容中是这样:

    $connection = ssh2_connect($host, $port);
    $sftp = ssh2_sftp($connection);
    $remoteFile = 'ssh2.sftp://' . intval($sftp) . '/var/file.text'
    echo $remoteFile
    file_put_contents($remoteFile, 'Content');  
    
    ssh2。sftp://2675/var/file.text

    分段故障

    如果没有演员阵容,它可以工作:

    $connection = ssh2_connect($host, $port);
    $sftp = ssh2_sftp($connection);
    $remoteFile = 'ssh2.sftp://' . $sftp . '/var/file.text'
    echo $remoteFile
    file_put_contents($remoteFile, 'Content');  
    
    ssh2。sftp://Resource id#2675/var/file.text


    你能在测试脚本中分离出来并运行它吗?在我的经验中,PHP中出现segfaults的最常见原因是递归函数无限递归。@DaveRandom这在安装了suhosin的情况下是不应该发生的。但segfault的另一个可能原因是很少测试的本机模块,如。。。ssh/sftp;)这就是我现在的处境。非常感谢。
    $connection = ssh2_connect($host, $port);
    $sftp = ssh2_sftp($connection);
    $remoteFile = 'ssh2.sftp://' . $sftp . '/var/file.text'
    echo $remoteFile
    file_put_contents($remoteFile, 'Content');