我是php和phpseclib的新手。
我打算用 php 编写一个 SSH 客户端作为我项目的一部分。我正在使用phpseclib库。
在我的项目中,公钥将被上传到仅支持openSSH和Putty密钥格式(公钥)的服务器(路由器)。
我使用 puttykeygen
创建了密钥对。我用php编写了一个SSH客户端。但是在显示加载一段时间后,它显示:注:I不要因为执行时间有限(30秒)而想
致命错误:在第 2699 行的 C:''xampp''htdocs''pages''Net''SSH2.php 中超过了 30 秒的最大执行时间
我的代码:
<?php
include('Net/SSH2.php');
include('Crypt/RSA.php');
$ssh = new Net_SSH2('remoteip');
$key = new Crypt_RSA();
$key->loadKey(file_get_contents('sshprivatekeyfile'));
if (!$ssh->login('admin', $key)) {
print_r($ssh->getError());
exit('Login Failed');
}
echo $ssh->exec('show clients');/any router commands/*
?>
检查此链接
延长最大执行时间,如下所示:
ini_set('max_execution_time', 300);
//300 秒
在 CLI (Linux) 上执行ping 192.168.10.1
。结束了吗?它不适合我。它只是永远不断地发送数据。所以这可能就是为什么它对你来说超时的原因。因为 ping 命令实际上永远不会结束。
有两种解决方案。
- 做
ping -c 4 192.168.10.1
- 在
$ssh->exec()
之前做$ssh->setTimeout(4)
。