PHP code example of acamposm / ping

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

    

acamposm / ping example snippets


use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

// Create an instance of PingCommand
$command = (new PingCommandBuilder('192.168.1.1'));

// Pass the PingCommand instance to Ping and run...
$ping = (new Ping($command))->run();

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

// Change the number of packets to send to 10
$command = (new PingCommandBuilder('192.168.1.1'))->count(10);

$ping = (new Ping($command))->run();

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

// Change interval to 0.5 seconds between each packet
$command = (new PingCommandBuilder('192.168.1.1'))->interval(0.5);

$ping = (new Ping($command))->run();

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

// Change packet size to 128
$command = (new PingCommandBuilder('192.168.1.1'))->packetSize(128);

$ping = (new Ping($command))->run();

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

// Change timeout to 10 seconds
$command = (new PingCommandBuilder('192.168.1.1'))->timeout(10);

$ping = (new Ping($command))->run();

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

// Change Time To Live to 128
$command = (new PingCommandBuilder('192.168.1.1'))->ttl(128);

$ping = (new Ping($command))->run();

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

$command = (new PingCommandBuilder('https://google.com'))->count(10)->packetSize(200)->ttl(128);

// Sample output from Windows based server
$ping = (new Ping($command))->run();

dd($ping);

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

$command = (new PingCommandBuilder('192.168.10.254'))->count(10)->packetSize(200)->ttl(120);

$ping = (new Ping($command))->run();

dd($ping);

use Acamposm\Ping\Ping;
use Acamposm\Ping\PingCommandBuilder;

$command = (new PingCommandBuilder('fe80::6c42:407d:af01:9567'))->count(10)->packetSize(200)->ttl(120);

$ping = (new Ping($command))->run();

dd($ping);