PHPackages                             ryangurn/ping - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. ryangurn/ping

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ryangurn/ping
=============

Ping uses the ICMP protocol's mandatory ECHO\_REQUEST datagram to elicit an ICMP ECHO\_RESPONSE from a host or gateway.

03

Since Mar 4Pushed 3y agoCompare

[ Source](https://github.com/ryangurn/ping)[ Packagist](https://packagist.org/packages/ryangurn/ping)[ RSS](/packages/ryangurn-ping/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PING for Laravel
================

[](#ping-for-laravel)

[![License](https://camo.githubusercontent.com/3cdcada9d77112ee6cedf427086b0918b56db3dbe51272c30960d0b03df471e5/68747470733a2f2f706f7365722e707567782e6f72672f6163616d706f736d2f70696e672f6c6963656e7365)](https://packagist.org/packages/acamposm/ping)[![Latest Stable Version](https://camo.githubusercontent.com/4a038531f3a32468dc1834176ce759ee048cb9219a457acb3f15f4527a48fffe/68747470733a2f2f706f7365722e707567782e6f72672f6163616d706f736d2f70696e672f762f737461626c65)](https://packagist.org/packages/acamposm/ping)[![StyleCI](https://camo.githubusercontent.com/88ce483d4a4c299366d99554d87bb3e2f835305a42d50d20abb9eae54d3d4335/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3235353133383436382f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/255138468)[![Total Downloads](https://camo.githubusercontent.com/f791e7bc87ad7368d39dcdd6f6fdb281aadf5d392ca5e76ae6a516a8a8cc5754/68747470733a2f2f706f7365722e707567782e6f72672f6163616d706f736d2f70696e672f646f776e6c6f616473)](https://packagist.org/packages/acamposm/ping)

[![Quality Gate Status](https://camo.githubusercontent.com/0f013f5ec849b1ff3a3fe144c5ffbf69d53e6d8752c323a9fbd4fb90ef727527/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d70696e67266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/summary/new_code?id=ping)[![Coverage](https://camo.githubusercontent.com/05c14143d0c8a148501d793974b2dfaba9fa3d751406c277c2f34e9718c0e6a3/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d70696e67266d65747269633d636f766572616765)](https://sonarcloud.io/summary/new_code?id=ping)[![Maintainability Rating](https://camo.githubusercontent.com/0ecc27e1eb410bdbf4e77ad5e36e365d8329ffc6ee37bc89a61a7610d2a4a4fc/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d70696e67266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/summary/new_code?id=ping)[![Security Rating](https://camo.githubusercontent.com/28d1483ffbe0d5daf1cb714431a9a746c85271369aa771765d0ebb7b9acd75ee/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d70696e67266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/summary/new_code?id=ping)

This ping class allow making ping request from Laravel applications, it is based on PING command from the linux iputils package.

ping uses the ICMP protocol's mandatory ECHO\_REQUEST datagram to elicit an ICMP ECHO\_RESPONSE from a host or gateway. ECHO\_REQUEST datagrams (pings) have an IP and ICMP header, followed by a struct timeval and then an arbitrary number ofpadbytes used to fill out the packet.

- [Installation](#installation)
- [Usage](#usage)
    - [Change Count](#change-count)
    - [Change Interval](#change-interval)
    - [Change Packet Size](#change-packet-size)
    - [Change Timeout](#change-timeout)
    - [Change Time To Live](#change-time-to-live)
- [Sample output](#sample-outputs)
- [Testing](#testing)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security &amp; Vulnerabilities](#security--vulnerabilities)
- [Standards](#standards)
- [Credits](#credits)
- [License](#license)

Installation
------------

[](#installation)

You can install the package via [composer](https://getcomposer.org/) and then publish the assets:

Prior to Ping 2.1.0 version you can install with:

```
composer require acamposm/ping

php artisan vendor:publish --provider="Acamposm\Ping\PingServiceProvider"
```

From Ping 2.1.0 version you can install with:

```
composer require acamposm/ping

php artisan ping:install
```

Usage
-----

[](#usage)

For basic usage you only need to create with an ip address as a first argument and run...

```
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();
```

### Change Count

[](#change-count)

Stop after sending count ECHO\_REQUEST packets. With deadline option, ping waits for count ECHO\_REPLY packets, until the timeout expires.

```
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();
```

### Change Interval

[](#change-interval)

Wait interval seconds between sending each packet. The default is to wait for one second between each packet normally, or not to wait in flood mode. Only super-user may set interval to values less than 0.2 seconds.

```
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();
```

### Change Packet Size

[](#change-packet-size)

Specifies the number of data bytes to be sent. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.

```
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();
```

### Change Timeout

[](#change-timeout)

Time to wait for a response, in seconds. The option affects only timeout in absence of any responses, otherwise ping waits for two RTTs.

```
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();
```

### Change Time To Live

[](#change-time-to-live)

ping only. Set the IP Time to Live.

```
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();
```

Sample outputs
--------------

[](#sample-outputs)

Here you can see three output samples of the ping command...

- The first with domain.
- The second with an IPv4 Address
- The third with an IPv6 Address

### Sample output on Windows based server to

[](#sample-output-on-windows-based-server-to-httpsgooglecom)

```
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);
```

```
{
    "host_status": "Ok",
    "raw": [
        "",
        "Haciendo ping a google.com [216.58.213.142] con 200 bytes de datos:",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "",
        "Estadísticas de ping para 216.58.213.142:",
        "    Paquetes: enviados = 10, recibidos = 10, perdidos = 0",
        "    (0% perdidos),",
        "Tiempos aproximados de ida y vuelta en milisegundos:",
        "    Mínimo = 36ms, Máximo = 37ms, Media = 36ms",
    ],
    "latency": 0.036,
    "rtt": {
        "avg": 0.036,
        "min": 0.036,
        "max": 0.037,
    },
    "sequence": {
        "0": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "1": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "2": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "3": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
        "4": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=37ms TTL=115",
        "5": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "6": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "7": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "8": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
        "9": "Respuesta desde 216.58.213.142: bytes=68 (enviados 200) tiempo=36ms TTL=115",
    },
    "statistics": {
        "packets_transmitted": 10,
        "packets_received": 10,
        "packets_lost": 0,
        "packet_loss": 0,
    },
    "options": {
        "host": "google.com",
        "count": 10,
        "packet_size": 200,
        "ttl": 120,
    },
    "time": {
        "start": {
            "as_float": 1596984650.5006,
            "human_readable": "09-08-2020 14:50:50.500600",
        },
        "stop": {
            "as_float": 1596984659.5802,
            "human_readable": "09-08-2020 14:50:59.580200",
        },
        "time": 9.08,
    },
}
```

### Sample output from Windows based server to local gateway IPv4

[](#sample-output-from-windows-based-server-to-local-gateway-ipv4)

```
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);
```

```
{
    "host_status": "Ok",
    "raw": [
        "",
        "Haciendo ping a 192.168.10.254 con 200 bytes de datos:",
        "Respuesta desde 192.168.10.254: bytes=200 tiempo
