🛰️ Minecraft PHP library for retrieving server query data
Required at least PHP 7.2
composer require php-minecraft/minecraft-query
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use PHPMinecraft\MinecraftQuery\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);
Library (socket logic) is inspired by xPaw/PHP-Minecraft-Query