|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58974 cannot represent a stream of type SSH2 Channel as a select()able descriptor
Submitted: 2009-12-03 10:28 UTC Modified: 2013-02-18 00:35 UTC
Avg. Score:3.5 ± 0.5
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:0 (0.0%)
From: samuel dot roze at gmail dot com Assigned:
Status: No Feedback Package: ssh2 (PECL)
PHP Version: 5_3 SVN-2009-12-03 (dev) OS: Debian 5.0
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2009-12-03 10:28 UTC] samuel dot roze at gmail dot com
In the description of ssh2_shell, there's:
"Open a shell at the remote end and allocate a stream for it."

So the result of this command must be a stream. Well, it's good, I'll use fgets, fwrite and stream_* functions ! BUT, the problem is that I can't use a SSH2 Stream with the stream_select function...

Reproduce code:
$session= ssh2_connect('localhost', 22);
ssh2_auth_password($session, 'samuel', 'password');

$shell = ssh2_shell($session);

$changed = stream_select($a = array($shell), $null, $null, 2); // Wait 2 seconds


Expected result:

Actual result:
Warning:  stream_select() []: cannot represent a
stream of type SSH2 Channel as a select()able descriptor in XX on line



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-27 12:31 UTC] samuel dot roze at gmail dot com
I developed a solution which you can see here: (French)
 [2011-06-23 10:58 UTC] adam at bantha dot co dot uk
Same problem - I hope this patch gets committed.
 [2011-06-23 12:24 UTC] samuel dot roze at gmail dot com
It can't be commited, because it need an libssh2 patch too...
 [2011-06-23 12:25 UTC] pierre dot php at gmail dot com
@samuel dot roze at gmail dot com

Can you send me the patch pls? or pierre . php 
at gmail dot com
 [2011-06-23 12:27 UTC] pierre dot php at gmail dot com
the patch>es<, will make it reviewed by the libssh2 developers 
as well
 [2012-06-14 22:27 UTC]
Hi Samuel,

I think your patch is very interesting. I think I see a problem though:

$changed = stream_select($a = array($shell), $null, $null, 2)

will return array($shell) when data is available on the ssh2 socket. This doesn't mean 
however that there is data on the $shell stream. It could be keepalive data, another 
tunnel or anything.

Have you thought about this? 

As long as reads are done while $shell stream is non-blocking, this shouldn't be too big 
of a problem. But: fread() from a stream returns 0 bytes could mean eof() according to the 
stream_select manual "a stream resource is also ready on end-of-file, in which case an 
fread() will return a zero length string"

Implementations where fread() returning '' might break.

Am I wrong here? What do you suggest?

Also: I think your patch could be rewritten to something that would only affect the ssh2 
extension. The extension creates the socket, then passes it to libssh2. If we keep a copy 
close to the stream, it could be implemented through changes in the extension only.
 [2013-02-18 00:35 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 "Open". Thank you.
 [2014-05-01 23:14 UTC] simon dot jackson at carringbush dot net
I have this problem also.

The patches by s dot roze could be done in a way that doesn't require a patch to libssh2 by having the rather dirty but effective change:

- int socket = libssh2_channel_socket_fd(abstract->channel);
+ int socket = abstract->channel->session->socket_fd;

Is this type of thing considered too dirty for consideration?

Our workaround is to sleep for 20ms when no stream has data. 20ms seems to work well for us and users can barely tell we are polling rather than being diven by an event.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Sep 26 03:05:53 2022 UTC