PHP code example of nathan818 / php-minecraft-pinger

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

    

nathan818 / php-minecraft-pinger example snippets



MinecraftPinger\MinecraftPinger;
use MinecraftPinger\MinecraftPingException;

$pinger = new MinecraftPinger('mc.hypixel.net', 25565); // Port is optional
try
{
    $pingResponse = $pinger->ping();
    echo 'There are ' . $pingResponse->players->online . ' players online on Hypixel!' . "\n";
}
catch (MinecraftPingException $e)
{
    // An error has occurred
    echo $e->getMessage();
}

composer