Stream 在phpseclib/SSH2中禁用阻塞?
我在多台服务器上运行一些命令,我希望它们都同时运行Stream 在phpseclib/SSH2中禁用阻塞?,stream,blocking,phpseclib,Stream,Blocking,Phpseclib,我在多台服务器上运行一些命令,我希望它们都同时运行 foreach($clust['hosts'] as $hostStr) { list($host, $port) = Str::rsplit($hostStr,':',2,22); $ssh = new \Net_SSH2($host, $port); if(!$ssh->login($username,$key)) { throw new \Exception("Could not conn
foreach($clust['hosts'] as $hostStr) {
list($host, $port) = Str::rsplit($hostStr,':',2,22);
$ssh = new \Net_SSH2($host, $port);
if(!$ssh->login($username,$key)) {
throw new \Exception("Could not connect to $username@$host:$port");
}
$connections[] = $ssh;
}
foreach($connections as $i=>$ssh) {
$ssh->exec('cd /path/to/my/project && hg up', function($str) {
echo $str;
});
echo "right after ls $i\n";
}
但这总是按顺序运行。我可以告诉
Net\u SSH2
是非阻塞的吗?您可以做的一件事是使用$ssh->setTimeout(1)
或$ssh->setTimeout(0.5)
或其他什么
您也可以使用
setTimeout
执行$ssh->write(…)
而不执行$ssh->read()
操作,这样不会中止命令,只会停止等待响应?是的-我相信这是正确的!您应该能够通过在单独的ssh窗口中执行ps aux | grep命令进行验证。