【发布时间】:2010-12-05 15:24:10
【问题描述】:
我正在开发一种工具,该工具使用 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,即使连接到 locahost 而不是远程系统也是如此。我可以通过将 ssh2_exec 调用更改为
$stream = ssh2_exec($this->connection,"~/iptsave; sleep .5");
但我担心出了点问题。
【问题讨论】:
-
您的问题得到答案了吗?