php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #56295 ssh2 doesn't close connections under apache
Submitted: 2005-02-11 18:26 UTC Modified: 2005-02-13 00:25 UTC
From: mario-dated-1110757160 dot 368950 at schmut dot com Assigned: pollita (profile)
Status: Closed Package: ssh2 (PECL)
PHP Version: 4.3.10 OS: linux fc2 or os x 10.3.7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mario-dated-1110757160 dot 368950 at schmut dot com
New email:
PHP Version: OS:

 

 [2005-02-11 18:26 UTC] mario-dated-1110757160 dot 368950 at schmut dot com
Description:
------------
I notice after running some php scripts that connects, execute a few statements and then finish, that there are lingering proccesses on the remote host a linux box FC2, where a ps ax looks like
  7102 ?        S      0:00 sshd: watchdog [priv]
  7104 ?        S      0:00 sshd: watchdog@notty

Upon closer inspection i find that this only happens when using libphp4 regardless of whether i dl load or preload using php.ini extension=ssh2. When running from the command line this does not happen at all. When using apache i have found no way around it. I've tried ssh2_exec($con, 'exit'), unset($con) and exit. There seems to be no hook for cleanup like there is when when the command line php proccess ends. And yes restarting apache frees the connections.


Reproduce code:
---------------
$con = ssh2_connect('hostname', 22);
ssh2_auth_password($con, 'user', 'passwd');
ssh2_exec($con, 'uname');
exit;

diff php.ini-dist php.ini 
82c95
< precision    =  12
---
> precision    =  14
154c167
< allow_call_time_pass_reference = On
---
> allow_call_time_pass_reference = Off
230c244
< max_execution_time = 30 
---
> max_execution_time = 60 
232c246,247
< memory_limit = 8M  
---
> memory_limit = 16M 
287c302
< log_errors = Off
---
> log_errors = On
382c397
< magic_quotes_gpc = On
---
> magic_quotes_gpc = Off
428c443
< extension_dir = "./"
---
> extension_dir = /usr/lib/php4
812,823c782
< ;session.save_path = /tmp
---
> session.save_path = /var/lib/php/session
877c828
< session.bug_compat_42 = 1
---
> session.bug_compat_42 = 0


Expected result:
----------------
i expect php under apache to close ssh connection upon completion of the script, like cli php does.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-11 18:40 UTC] mario-dated-1110757160 dot 368950 at schmut dot com
changed email to dated so notifications don't get sacked by the spam filter
 [2005-02-13 00:25 UTC] pollita@php.net
This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pecl.php.net.

In case this was a pecl.php.net website problem, the change will show
up on the website in short time.
 
Thank you for the report, and for helping us make PECL better.

Look for this fix in 0.7
 [2006-05-15 14:28 UTC] mkoponick at redhawk dot info
Hello,

I'm running into the same issue, although I'm running 0.10.

I did see where there was a patch for SSH2.C (1.16) but don't know if I should add that to the mix.

Thoughts?

Thanks in advance,

Mike
 [2007-12-14 13:16 UTC] christoph dot hintermueller at psi dot ch
This bug is partially still persitent in php_ssh2 0.10, especially if 
mod php abborts  ord dies due to some error, or when users 
abborts the request triggering the ssh connection. If the streams 
to remote shell or exec are not closed the whole connection will 
perist. 
Looking tho she sources the shutdown function unregisters from 
php but forgets to explicitly check if the streams are still open 
and forces them to be closed if nobody sent an exit or logout 
command to shell. 
 
So please add some force logout and disconnect when php 
terminates.
 [2010-02-26 22:45 UTC] info at busign dot nl
This bug still exists in ssh2, latest:

[Server @ NL01] ~ $ w
 04:43:18 up 5 min,  5 users,  load average: 0.02, 0.09, 0.06
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    **.**.c 04:43    0.00s  0.00s  0.00s -bash
root     pts/1    **.**.c 04:40    3:17   0.00s  0.00s -bash
root     pts/2    ip51cc333e.speed 04:39    0.00s  0.00s  0.00s w
root     pts/3    **.**.c 04:40    3:17   0.01s  0.01s -bash
root     pts/4    **.**.c 04:43    0.00s  0.00s  0.00s -bash


I just rebooted my server, because there were 35 ssh sessions active... ?

**.** = php script.

I even use ssh2_exec($conn, 'exit');, this doesnt work allways...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 13:01:29 2024 UTC