PHP code example of php-minecraft / minecraft-query

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

    

php-minecraft / minecraft-query example snippets


declare(strict_types=1);

ftQuery\MinecraftQueryResolver;

$resolver = new MinecraftQueryResolver('play.minecord.net', 25565);

$result = $resolver->getResult();


$resolver = new MinecraftQueryResolver('play.minecord.net', 25565);

$resolver->retrieveDataPre17();

$result = $resolver->getResult();


$resolver = new MinecraftQueryResolver('play.minecord.net', 25565);

$result = $resolver->getResult($tryOldQueryProtocolPre17 = true);


$result->getMaxPlayers() // integer
$result->getOnlinePlayers() // integer
$result->getPlayersSample() // array (players -> sample at https://wiki.vg/Server_List_Ping)
$result->getVersion() // string
$result->getProtocolVersion() // integer
$result->getMessageOfTheDay() // string
$result->getLatency() // integer (ms)
$result->getFavicon() // string or null

// use this cosntructor if you dont want separate address to host and port
$resolver = MinecraftQueryResolver::fromAddress('play.minecord.net');

// use this method if you want raw data in array retrieved from minecraft server
$rawData = $resolver->getRawData();

// use this method if you want construct MinecraftQueryResult from raw data
$result = MinecraftQueryResult::fromRawData($rawData);

composer