PHP code example of geerlingguy / ping

1. Go to this page and download the library: Download geerlingguy/ping library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

geerlingguy / ping example snippets


$host = 'www.example.com';
$ping = new \JJG\Ping($host);
$latency = $ping->ping();
if ($latency !== false) {
  print 'Latency is ' . $latency . ' ms';
}
else {
  print 'Host could not be reached.';
}

$ttl = 128;
$timeout = 5;
$ping = new \JJG\Ping($host, $ttl, $timeout);

$ping = new \JJG\Ping($host);
$ping->setTtl(128);
$ping->setTimeout(5);

$ping = new \JJG\Ping($host);
...
$ping->setHost('www.anotherexample.com');