|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71047 file_exists seems to be broken in php7
Submitted: 2015-12-07 07:36 UTC Modified: 2017-11-05 04:22 UTC
Avg. Score:4.5 ± 0.6
Reproduced:16 of 17 (94.1%)
Same Version:11 (68.8%)
Same OS:9 (56.2%)
From: mmucklo at gmail dot com Assigned: langemeijer (profile)
Status: No Feedback Package: ssh2 (PECL)
PHP Version: 7.0.0 OS: Ubuntu 15.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
31 + 33 = ?
Subscribe to this entry?

 [2015-12-07 07:36 UTC] mmucklo at gmail dot com
I've tried to use this plugin on PHP7 (compiling from trunk / master).

It compiles and installs.  I can connect fine.

However it seems the file_exists function no longer reports true when using an ssh2_sftp resource handle.

Test script:
if (!function_exists("ssh2_connect")) die("function ssh2_connect doesn't exist");
// log in at on port 22
if(!($con = ssh2_connect("wherever", 22))){
    echo "fail: unable to establish connection\n";
} else {
    // try to authenticate with username root, password secretpassword
    if(!ssh2_auth_pubkey_file($con, "someuser", "/path/to/.ssh/", "/path/to/.ssh/id_rsa")) {
        echo "fail: unable to authenticate\n";
    } else {
        // allright, we're in!
        echo "okay: logged in...\n";

        // execute a command
        if (!($stream = ssh2_exec($con, "ls -al" ))) {
            echo "fail: unable to execute command\n";
        } else {
            echo "what came back from command:\n";
            // collect returning data from command
            stream_set_blocking($stream, true);
            $data = "";
            while ($buf = fread($stream,4096)) {
                $data .= $buf;
            echo $data;
            $sftp = ssh2_sftp($con);
            echo "\n";
            $result = file_exists("ssh2.sftp://$sftp/path/to/somefile");
            echo "\n";
            echo "\n";
            echo "\n";
            echo "file_exists: " . ($result ? "yes" : "no ");
            echo "\n";

Expected result:

file_exists: yes

Actual result:

file_exists: no


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-10-14 08:18 UTC] fashionretailshop01 at gmail dot com - fake  ray ban sunglasses - wholesale ray ban sunglasses - shoes - ShoesBootsCheap Sitemap
 [2016-10-14 08:19 UTC] fashionretailshop01 at gmail dot com - Cheap NFL Jerseys - Cheap Jerseys Free shipping - Custom NFL Jerseys - Discount NFL Jerseys
 [2016-12-01 14:28 UTC] hranicka at outlook dot com
ssh2_* functions requires SSH2 extension.

For PHP 7, you need PECL SSH2 v1.0.0 or greather.

It was not exist at 2015-12-07 but now is available.

I've found this issue because of I've used PECL extension until today. For PHP 7.0.12 worked fine, but in 7.0.13 is broken. And I've has the same problem.

Solution: Compile latest versions where the bug with newest version is fixed:
 [2017-02-06 19:39 UTC]
This might well be fixed with this commit:

Could you try current master and see if the problem is solved?
 [2017-02-06 19:57 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: langemeijer
 [2017-03-29 02:23 UTC] james at james dot tl
I was having this problem with pecl-ssh2 1.0.0 and php 7.0.15, but I am not having it anymore with pecl-ssh master.
 [2017-10-24 06:49 UTC]
-Status: Assigned +Status: Feedback
 [2017-11-05 04:22 UTC] pecl-dev at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Aug 15 13:03:41 2022 UTC