You are here

public function Cleantalk::httpPing in Anti Spam by CleanTalk 7.5

Same name and namespace in other branches
  1. 7 cleantalk.module \Cleantalk::httpPing()
  2. 7.2 cleantalk.module \Cleantalk::httpPing()
  3. 7.4 src/Cleantalk.php \Cleantalk::httpPing()

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 632

Class

Cleantalk
Cleantalk Base class

Code

public 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;
}