I am running a command using ssh2_exec, but looks like it runs the $stream2 before the end of $stream1 process. How do I run $stream2 only after the end of $stream1?
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream1= ssh2_exec($connection, 'command to run');
$stream2 = ssh2_exec($connection, 'command to run 2');
?>
the fact that blocking isn't enabled by default is stupid. this is why i like SSH by phpseclib so much better. stuff just works as expected with phpseclib. eg.
Problem Solved:
@Barmar proposed me to look at php.net/manual/en/function.ssh2-exec.php#59324
I solved the problem by:
Read everything from the first stream. When it finishes, you know the command is done.