【发布时间】:2013-11-22 11:57:05
【问题描述】:
我为这个问题奋斗了2周,我使用phpseclib从网络向路由器发送命令以执行不同的行为,其中之一是重启路由器的网络接口,我很好重启网络界面,但运行命令后,整个 apache 冻结,并且不响应任何其他 http 请求,我使用的是 phpseclib 0.3.5。首先非常感谢您的帮助
Javascript
$.ajax({
ajax work here to call the runCMDAdvance function and with timeout specified
});
PHP
//function to run the command
function runCMDAdvance($sshIP, $cmd, $tVal,$tarIP){
$ssh = new Net_SSH2($sshIP,$this->port);
if (!$ssh->login($this->username, $this->password)){
echo "Bad Login";
return false;
}
//set timeout for running ssh command, should be done after the ssh object has been initialized
$tVal>0 ? $ssh->setTimeout($tVal):"";
$res = $ssh->exec($cmd);
$ssh->disconnect();
return $res;
}
$cmd = INCL_PATH . ' && ' . '/sbin/uci commit network && '.'/sbin/uci commit dhcp && '.'/etc/init.d/network restart 2>&1 && exit'."\n";
$res = $ssh2_conn->runCMDAdvance($ip, $cmd, 20, "");
我的猜测是,当执行重启网络接口时,AP 断开连接并以某种方式使 phpseclib 崩溃,但我不知道如何解决这个问题。任何帮助将不胜感激。
更新: 我刚刚做了一个实验,每当我运行上面的 ssh 命令时,web 服务器需要 15.3 分钟来处理另一个请求...... http://i102.photobucket.com/albums/m112/ihmcjacky/Mobile%20Uploads/000_zpscc73f7f0.jpg
【问题讨论】:
-
如果网络接口正在重新启动,那么
setTimeout调用将不会执行任何操作,因为此时 phpseclib 将失去它自己的连接,而 phpseclib 正在检查有多少时间过去 - 不是服务器。真的,我认为这里的问题是您正在重新启动网卡。听起来像所有其他命令 - 除了这个 - 有效吗?
标签: php linux apache phpseclib network-interface