PHP-ssh2_exec:等待进程结束,然后再运行

我正在使用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');

?>

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...