You are here

function Cleantalk::httpPing in Anti Spam by CleanTalk 8

Function to check response time param string

Return value

int

1 call to Cleantalk::httpPing()
Cleantalk::get_servers_ip in src/Cleantalk.php
Function DNS request

File

src/Cleantalk.php, line 597

Class

Cleantalk
Cleantalk class create request

Namespace

Drupal\cleantalk

Code

function httpPing($host) {

  // Skip localhost ping cause it raise error at fsockopen.
  // And return minimun value
  if ($host == 'localhost') {
    return 0.001;
  }
  $starttime = microtime(true);
  $file = @fsockopen($host, 80, $errno, $errstr, $this->server_timeout);
  $stoptime = microtime(true);
  $status = 0;
  if (!$file) {
    $status = -1;

    // Site is down
  }
  else {
    fclose($file);
    $status = $stoptime - $starttime;
    $status = round($status, 4);
  }
  return $status;
}