PHP code example of pifeifei / ping

1. Go to this page and download the library: Download pifeifei/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/ */

    

pifeifei / ping example snippets


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

$ping = new Ping();
$ping->setHost($host)
     ->setTtl(128)
     ->setTimeout(5)
     ->setPort(80)
     ->ping();

$ping = new Ping();
...
$ping('www.anotherexample.com');
$ping('example2.com');