php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #58845 ssh2 pecl package blocking/unblocking read issue
Submitted: 2009-08-31 09:45 UTC Modified: 2012-06-14 21:59 UTC
From: pkleef at openlinksw dot com Assigned:
Status: Not a bug Package: ssh2 (PECL)
PHP Version: 5.2.10 OS: Windows
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: pkleef at openlinksw dot com
New email:
PHP Version: OS:

 

 [2009-08-31 09:45 UTC] pkleef at openlinksw dot com
Description:
------------
Currently the ssh2 extension sets is_blocking = 0 to use 
non-blocking reads. This causes all kinds of problems 
reading output back from a ssh2 server.

I have seen another bugreport that may fix part of the 
problems with the blocking read, but since the underlying 
ssh2 library uses blocking mode by default, we are wondering 
what the reason for non-blocking might be. 

i have attached a small patch that sets this extension to 
use blocking reads.

As a side note you may want to mention that users should get 
the absolute latest libssh2 v1.2 package from 
(http://libssh2.haxx.se/download/libssh2-1.2.tar.gz) since 
this contains a number of important fixes for downloading 
large output from the server. 





Reproduce code:
---------------
* default to blocking connections; this is the what libssh2 does by default.
diff -up ssh2-0.11.0/ssh2.c.orig ssh2-0.11.0/ssh2.c
--- ssh2-0.11.0/ssh2.c.orig     2008-12-02 21:50:10.000000000 +0100
+++ ssh2-0.11.0/ssh2.c  2009-08-31 10:23:27.000000000 +0200
@@ -790,7 +790,7 @@ PHP_FUNCTION(ssh2_forward_accept)
        channel_data = emalloc(sizeof(php_ssh2_channel_data));
        channel_data->channel = channel;
        channel_data->streamid = 0;
-       channel_data->is_blocking = 0;
+       channel_data->is_blocking = 1;
        channel_data->session_rsrc = data->session_rsrcid;
        channel_data->refcount = NULL;

diff -up ssh2-0.11.0/ssh2_fopen_wrappers.c.orig ssh2-0.11.0/ssh2_fopen_wrappers.c
--- ssh2-0.11.0/ssh2_fopen_wrappers.c.orig      2008-12-02 22:06:54.000000000 +0100
+++ ssh2-0.11.0/ssh2_fopen_wrappers.c   2009-08-31 10:23:22.000000000 +0200
@@ -442,7 +442,7 @@ static php_stream *php_ssh2_shell_open(L
        channel_data = emalloc(sizeof(php_ssh2_channel_data));
        channel_data->channel = channel;
        channel_data->streamid = 0;
-       channel_data->is_blocking = 0;
+       channel_data->is_blocking = 1;
        channel_data->session_rsrc = resource_id;
        channel_data->refcount = NULL;

@@ -687,7 +687,7 @@ static php_stream *php_ssh2_exec_command
        channel_data = emalloc(sizeof(php_ssh2_channel_data));
        channel_data->channel = channel;
        channel_data->streamid = 0;
-       channel_data->is_blocking = 0;
+       channel_data->is_blocking = 1;
        channel_data->session_rsrc = resource_id;
        channel_data->refcount = NULL;

@@ -875,7 +875,7 @@ static php_stream *php_ssh2_scp_xfer(LIB
        channel_data = emalloc(sizeof(php_ssh2_channel_data));
        channel_data->channel = channel;
        channel_data->streamid = 0;
-       channel_data->is_blocking = 0;
+       channel_data->is_blocking = 1;
        channel_data->session_rsrc = resource_id;
        channel_data->refcount = NULL;

@@ -1086,7 +1086,7 @@ static php_stream *php_ssh2_direct_tcpip
        channel_data = emalloc(sizeof(php_ssh2_channel_data));
        channel_data->channel = channel;
        channel_data->streamid = 0;
-       channel_data->is_blocking = 0;
+       channel_data->is_blocking = 1;
        channel_data->session_rsrc = resource_id;
        channel_data->refcount = NULL;



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-14 21:59 UTC] langemeijer@php.net
-Status: Open +Status: Not a bug
 [2012-06-14 21:59 UTC] langemeijer@php.net
Indeed, default behaviour is non-blocking.

You can set an output stream blocking if you want:

$exec = ssh2_exec($connection, '/path/to/application');
stream_set_blocking($exec, true);
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 07:01:31 2024 UTC