php.net |  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
Votes:6
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: samuel dot roze at gmail dot com
New email:
PHP Version: OS:

 

 [2009-12-03 10:28 UTC] samuel dot roze at gmail dot com
Description:
------------
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:
---------------
<?php
$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

var_dump($changed);
?>

Expected result:
----------------
int(1)

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

int(0)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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:
http://www.d-sites.com/2009/12/06/cannot-represent-a-stream-of-type-ssh2-channel-as-a-selectable-descriptor/ (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? pierre@php.net 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] langemeijer@php.net
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.

1
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?

2
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-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 10:01:28 2024 UTC