|  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
 [2007-12-14 13:46 UTC] christoph dot hintermueller at psi dot ch
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 
I'm using mod_php for appache 1.3.27. 

Reproduce code:
$session = ssh2_connect("localhost","2222");
$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" ) {
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. 
echo "done with whatever";

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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-10 14:28 UTC]
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-2020 The PHP Group
All rights reserved.
Last updated: Wed Jul 08 09:01:26 2020 UTC