function GetLatency($host, $port) { /** -> composer.json ====================================== { "minimum-stability": "dev", "require": { "geerlingguy/ping": "1.*@dev" } } ====================================== **/ #$host = "www.google.com.tr"; #$port = 443; $handle = new Ping($host); if (isset($port)) { $handle->setPort($port); } $latency = $handle->ping("fsockopen"); $status = array("<div class='online'> {$latency} ms </div>", "<div class='offline'>Error</div>"); if ($latency !== false) { return $status[0]; } else { return $status[1]; } }
public function testPort() { $port = 2222; $ping = new Ping($this->reachable_host); $ping->setPort($port); $this->assertEquals($port, $ping->getPort()); }
/** * @param int $port * @return $this */ public function setPort($port) { parent::setPort($port); return $this; }
/** -> composer.json ====================================== { "minimum-stability": "dev", "require": { "geerlingguy/ping": "1.*@dev" } } ====================================== **/ /** * vendor/autoload.php dosyası Composer tarafından * oluşturulmaktadır. */ require "vendor/autoload.php"; use JJG\Ping; # Host adresi ( IP adreside girilebilir. ) $host = "www.google.com.tr"; # Port numarası ( girmesenizde olur. ) $port = 443; $handle = new Ping($host); if (isset($port)) { $handle->setPort($port); } $latency = $handle->ping("fsockopen"); if ($latency !== false) { echo "Latency is {$latency} ms"; } else { echo "Host could not be reached."; }