正在使用ssh2_exec运行命令,但看起来像是在$stream1进程结束之前运行$stream2。 我如何仅在$stream1退出后运行$stream2?
$connection=ssh2_connect (外壳. example.com),22 );
sh2_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
我用以下方法解决了这个问题:
$connection=ssh2_connect (外壳. example.com),22 );
sh2_auth_password($connection,' username ',' password ' );
$stream1=ssh2_exec($connection,' command to run ' );
stream_set_blocking($stream1,true );
//thecommandmaynotfinishproperlyifthestreamisnotreadtoend
$ output=stream _ get _ contents ($ stream1);
$stream2=ssh2_exec($connection,' command to run 2';
?
标签: php,ssh
资料来源: https://codeday.me/bug/2019 10 11/1892960.html