If you want to run many exec orders throught ssh2 in the same process using the same variable $stream for exemple and to read the output for each order, you must close the stream after each order else you will not be able to read the next order output.
<?php
$stream=ssh2_exec($conn_id,"/usr/bin/ls .");
stream_set_blocking( $stream, true );
$cmd=fread($stream,4096);
fclose($stream);
if(ereg("public_html",$cmd)){
}
$stream=ssh2_exec($conn_id,"/usr/bin/ls public_html");
stream_set_blocking( $stream, true );
$cmd=fread($stream,4096);
fclose($stream);
if(ereg("images",$cmd)){
}
$stream=ssh2_exec($conn_id,"/usr/bin/ls public_html/images");
stream_set_blocking( $stream, true );
$cmd=fread($stream,4096);
fclose($stream);
if(ereg("blabla",$cmd)){
}
?>