public function Cleantalk::get_servers_ip in Anti Spam by CleanTalk 7.2
Same name and namespace in other branches
- 7.5 src/Cleantalk.php \Cleantalk::get_servers_ip()
- 7 cleantalk.module \Cleantalk::get_servers_ip()
- 7.4 src/Cleantalk.php \Cleantalk::get_servers_ip()
Function DNS request
Parameters
$host:
Return value
array
1 call to Cleantalk::get_servers_ip()
- Cleantalk::httpRequest in ./
cleantalk.module - httpRequest
File
- ./
cleantalk.module, line 945 - Main CleanTalk integration module functions.
Class
- Cleantalk
- Cleantalk class create request
Code
public function get_servers_ip($host) {
$response = null;
if (!isset($host)) {
return $response;
}
if (function_exists('dns_get_record')) {
$records = dns_get_record($host, DNS_A);
if ($records !== FALSE) {
foreach ($records as $server) {
$response[] = $server;
}
}
}
if (count($response) == 0 && function_exists('gethostbynamel')) {
$records = gethostbynamel($host);
if ($records !== FALSE) {
foreach ($records as $server) {
$response[] = array(
"ip" => $server,
"host" => $host,
"ttl" => $this->server_ttl,
);
}
}
}
if (count($response) == 0) {
$response[] = array(
"ip" => null,
"host" => $host,
"ttl" => $this->server_ttl,
);
}
else {
// $i - to resolve collisions with localhost
$i = 0;
$r_temp = null;
$fast_server_found = false;
foreach ($response as $server) {
// Do not test servers because fast work server found
if ($fast_server_found) {
$ping = $this->min_server_timeout;
}
else {
$ping = $this
->httpPing($server['ip']);
$ping = $ping * 1000;
}
// -1 server is down, skips not reachable server
if ($ping != -1) {
$r_temp[$ping + $i] = $server;
}
$i++;
if ($ping < $this->min_server_timeout) {
$fast_server_found = true;
}
}
if (count($r_temp)) {
ksort($r_temp);
$response = $r_temp;
}
}
return $response;
}