我正在开发一个工具,它使用 PECL SSH2 扩展通过 SSH2 从远程主机读取 iptables 配置。我能够成功连接到主机、进行身份验证并执行命令。我遇到的问题是有时该流不包含任何数据。
/**
* Load the current firewall configuration
* @return bool
*/
public function loadRules() {
$stream = ssh2_exec($this->connection,"~/iptsave;");
stream_set_blocking($stream,true);
$iptablesSave = stream_get_contents($stream);
if(empty($iptablesSave)) {
return false;
}
parent::restore($iptablesSave);
return true;
}
大约25%的时间,loadRules()
即使连接到本地主机而不是远程系统,也会返回 false。我能够通过改变来解决这个问题ssh2_exec
拨电至
$stream = ssh2_exec($this->connection,"~/iptsave; sleep .5");
但我担心出了什么问题。
phpSecLib 或许可以提供帮助:
根据,它总是返回输出,与 ssh2.so 不同。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)