我已经为这个问题挣扎了两周,我使用phpseclib从web向路由器发送命令来执行不同的行为,其中之一是重新启动路由器的网络接口,我很好地重新启动网络接口,但运行命令后,整个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
致neubert:感谢您的反馈,实际上大多数命令都使用phpseclib运行良好。
提到服务器没有响应,如果这是不可避免的,我可以缩短服务器挂起的"死区"吗?或者有其他可行的解决方案吗?