我正在使用ssh2_exec运行命令,但看起来它在$stream1进程结束之前运行$stream2.如何仅在$stream1结束后运行$stream2?
<?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');
?>
解决方法:
问题解决了:
@Barmar建议我看看PHP.net/manual/en/function.ssh2-exec.PHP#59324
<?PHP
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_password($connection, 'username', 'password');
$stream1= ssh2_exec($connection, 'command to run');
stream_set_blocking($stream1, true);
// The command may not finish properly if the stream is not read to end
$output = stream_get_contents($stream1);
$stream2 = ssh2_exec($connection, 'command to run 2');
?>