我正在使用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');
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。