php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57971 PHP buffers not working after opening shell connection
Submitted: 2007-12-14 13:46 UTC Modified: 2009-01-10 14:28 UTC
From: christoph dot hintermueller at psi dot ch Assigned:
Status: Not a bug Package: ssh2 (PECL)
PHP Version: 4.3.8 OS: Linux
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: christoph dot hintermueller at psi dot ch
New email:
PHP Version: OS:

 

 [2007-12-14 13:46 UTC] christoph dot hintermueller at psi dot ch
Description:
------------
When opening a shell on remote host with ssh2_shell than 
normal php output buffer mechanism does not work any more. 
None of the commands operation on the active ob_buffer works 
as exspected and describe by the PHP manual. One has to 
explicitly open PHP://STDOUT and frwirte to it to send messages 
to the client or fclose the stream returned by ssh_shell again. 
Which is not desireable when you have to analyze the output of 
remote programm before sending (new) commands to the 
shell/program as opening a pseudo terminal may take some time. 
 
Thus i ask you to either add some ssh2_proc function which 
behaves like proc_open but running remote shell/program 
machine instead of local shell/program or fix ssh2_shell that it 
returns streams which do not interfeer with default PHP://STDIN 
PHP://STDOUT and PHP://STDERR. 
 
I'm using mod_php for appache 1.3.27. 
 
 

Reproduce code:
---------------
$session = ssh2_connect("localhost","2222");
ssh2_auth_password($session,$username,$password);
$channel = ssh2_shell($session,"linux",NULL,1024,1,SSH2_TERM_UNIT_CHARS);
echo "this is some message to client<BR/>\n";
stream_set_blocking($channel, true);
fprintf($channel,"echo -e \"a\\nb\\nc\\nd" \necho ENDOFOUTPUT\n")
sleep(200000); // this is necessary in order not to read back
// commands sent to client before client has received them. 
while ( ( $line = fread($channel) 
 ) !== false ) {
   echo "line \"$line\"<BR/>\n";
   if ( trim($line) == "ENDOFOUTPUT" ) {
    break;
  }
}
fprintf($channel,"echo done\nexit\nlogout\n");
sleep(200000); // this is necessary in order not to read back
// commands sent to client before client has received them. 
fclose($channel)
echo "done with whatever";

Expected result:
----------------
this is some message to client 
line "a" 
line "b" 
line "c" 
line "d" 
line "ENDOFOUTPUT" 
done with whatever 

Actual result:
--------------
If at all than i see: 
 
done with whatever 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-10 14:28 UTC] mikesul@php.net
Your reproduce code has bugs in it that might cause things like that. Ignoring the parse errors, it's sleeping for 200000 seconds -- twice. And the fread() call is missing the second argument, which will cause it to fail (and return false) on the first execution.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Sep 17 09:01:26 2019 UTC