您好我想知道是否可以通过服务器阵列从多个服务器获得对PHP的响应?
我正在尝试创建一个脚本,它将在多个服务器上grep文本,每个服务器都有不同的文件,但我有一个列表,列出了存储在list.txt中的每个服务器的目录中的所有文件。我正在尝试尽可能快地进行搜索,我目前正在使用ripgrep来搜索我的数据。
<?php
if (!function_exists('ssh2_connect'))
{
die("Install ssh2 module.\n");
}
if (isset($_GET['command'], $_GET['text'], $_GET['down'])) {
$SERVERS = array(
"10.0.0.3" => array("root", "password")
"10.0.0.4" => array("root", "password")
"10.0.0.5" => array("root", "password")
"10.0.0.6" => array("root", "password")
);
class ssh2 {
var $connection;
function __construct($host, $user, $pass) {
if (!$this->connection = ssh2_connect($host, 22))
throw new Exception("Error connecting to server");
if (!ssh2_auth_password($this->connection, $user, $pass))
throw new Exception("Error with login credentials");
}
function exec($cmd) {
if (!ssh2_exec($this->connection, $cmd))
throw new Exception("Error executing command: $cmd");
ssh2_exec($this->connection, 'exit');
unset($this->connection);
}
}
if($_GET['command'] == "Download") { $command = "wget http://10.0.0.7/data/{$down}.db"; }
elseif($_GET['command'] == "Search") { $command = "while read filename; do grep {$text} "$filename"; done < list.txt" }
else die();
foreach ($SERVERS as $server=>$credentials) {
$disposable = new ssh2($server, $credentials[0], $credentials[1]);
$disposable->exec($command);
echo "<pre>$disposable</pre>";
}
}
?>