1. Go to this page and download the library: Download spatie/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/ */
use Spatie\Ping\Ping;
$result = (new Ping('8.8.8.8'))->run();
if ($result->isSuccess()) {
echo "Ping successful! Average response time: {$result->averageResponseTimeInMs()}ms";
} else {
echo "Ping failed: {$result->error()?->value}";
}
$result = (new Ping(
hostname: '8.8.8.8',
timeoutInSeconds: 5, // seconds
count: 3, // number of packets
intervalInSeconds: 1.0, // seconds between packets
packetSizeInBytes: 64, // how big the packet is we'll send to the server
ttl: 64, // time to live (maximum number of hops)
showLostPackets: true // report outstanding replies (Linux only, enabled by default)
))->run();
// Enabled by default on Linux (ignored on macOS)
$result = (new Ping('8.8.8.8'))->run();
// Explicitly disable
$result = (new Ping('8.8.8.8'))
->showLostPackets(false)
->run();
// Explicitly enable
$result = (new Ping('8.8.8.8'))
->showLostPackets(true)
->run();
use Spatie\Ping\Ping;
$result = (new Ping('non-existent-host.invalid'))->run();
if (! $result->isSuccess()) {
return $result->error() // returns the enum case Spatie\Ping\Enums\PingError::HostnameNotFound
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.