$stream1= ssh2_exec($connection, 'command to run');
stream_get_contents($stream1); // Wait for command to finish
fclose($stream1);
$stream2 = ssh2_exec($connection, 'command to run 2');
şöyle bir şey var aradığınız bu mu anlamadım ama stackoverflow'da bir kaçtane daha var örnek.