|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56948 Unable to close connection before end of script when using ssh2_fetch_stream
Submitted: 2006-04-10 16:57 UTC Modified: 2012-10-06 09:22 UTC
From: mplourde at digicom dot ca Assigned:
Status: No Feedback Package: ssh2 (PECL)
PHP Version: 5.0.5 OS: Linux kernel 2.4.20-19.7
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-04-10 16:57 UTC] mplourde at digicom dot ca
/* Part of phpinfo() */

Registered PHP Streams => php, file, http, ftp, tftp, telnet, dict, ldap, https, ftps, compress.zlib,, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp


libssh2 version => 0.12
banner => SSH-2.0-libssh2_0.12
remote forwarding => enabled
hostbased auth => enabled
polling support => enabled
publickey subsystem => enabled

/* End Part of phpinfo() */

I try ssh connection using php script to do some remote command and retrieve result of it. I got many connection on differents servers to do in a endless loop (act like a daemon), so i have to disconnect everytime the connection is useless or at the 2nd time loop there will be duplicate connection and at the 3rd time loop ... And someday (in fact it take some minute) sshd  will refuse connection. 

Reproduce code:
if($con_ssh = ssh_connect("x.x.x.x"))exit(1);
if(!ssh_auth_pubkey_file($con_ssh,'root','/root/.ssh/','/root/.ssh/id_dsa', ''))exit(1);
$stdio = ssh2_shell($con_ssh,"xterm");
$stderr = ssh2_fetch_stream($stdio,SSH2_STREAM_STDERR);

Expected result:
When open and another xterm console on the remote server, "who" command must show the shell is on while the first sleep is on and the "ps" command must show one more sshd process. After closing both stream (while the second sleep hold on), shell is off but there is still one more sshd process. After unset the ssh session ressource ($con_ssh), the  "one more sshd process" have disapear.
Connection must ended when stream are close and ssh2 session ressource is unset. 

Actual result:
Connection is keep alive until i force the end of script (daemon), this result in incapacity to connect to remote server since sshd refuse connection (too many). When i comment all line using stderr and ssh2_fetch_stream, the connection end normally as describe in the expected result.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-12 09:23 UTC] mplourde at digicom dot ca
It could be a bad utilisation of the function too, but i didn't found any documentation on how to use it.
 [2012-02-24 13:27 UTC] bart dot de dot lange at live dot nl
It said that it needs a ICO.dll file and that is mising
 [2012-06-13 20:55 UTC]
-Status: Open +Status: Feedback
 [2012-06-13 20:55 UTC]
I cannot reproduce this issue with ssh2 extension version 0.11.3 and a libssh2 
1.4.2. Please try again, and post the details in this bug.
 [2012-10-06 09:22 UTC]
-Status: Feedback +Status: No Feedback
 [2012-10-06 09:22 UTC]
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 "Open". Thank you.

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Oct 07 04:04:13 2022 UTC