我有一個可移植的版本的Apache和php7在Windows phpseclib1.0.7。我想擴展lib以便利用ssh。利用從網站股票腳本 測試PHP SSH2:超過30秒的最大執行時間
<?php
include('Net/SSH2.php');
$ssh = new Net_SSH2('-Redacted-');
if (!$ssh->login('-Redacted-', '-Redacted-')) {
exit('Login Failed');
}
echo $ssh->read('[email protected]:~$');
$ssh->write("sudo ls -la\n");
$output = $ssh->read('#[pP]assword[^:]*:|[email protected]:~\$#',
NET_SSH2_READ_REGEX);
echo $output;
if (preg_match('#[pP]assword[^:]*:#', $output)) {
$ssh->write("password\n");
echo $ssh->read('[email protected]:~$');
}
?>
即使缺少信息,則應該拋出一個錯誤,而是它給了我
PHP Fatal error: Maximum execution time of 30 seconds exceeded in
C:\Users\-Redacted-\Desktop\Apache2.2\htdocs\Net\SSH2.php on line 2358
這裏是SSH2.php開始行2351
if (isset($this->keyboard_requests_responses)) {
for ($i = 0; $i < $num_prompts; $i++) {
if (strlen($response) < 4) {
return false;
}
extract(unpack('Nlength', $this->_string_shift($response, 4)));
// prompt - ie. "Password: "; must not be empty
Line 2358---- $prompt = $this->_string_shift($response, $length);
//$echo = $this->_string_shift($response) != chr(0);
foreach ($this->keyboard_requests_responses as $key => $value) {
if (substr($prompt, 0, strlen($key)) == $key) {
$responses[] = $value;
break;
}
}
}
}
沒有人有任何想法如何解決?
你可以ping遠程主機嗎? – apokryfos
是否確定您的服務器ssh open是否打開? –
膩子與遠程主機一起工作得很好。 – MoonEater916