Minecraft RCON Client

PackagePHP

RCON lets you send console commands to a Minecraft server over the network. This package is a small RCON client for PHP, with no dependencies.

Minecraft splits a response that is longer than 4096 bytes into several packets. The client reads all the packets of a response and returns the full output as one string, so the output of commands such as help and data get entity is not cut off.

sendCommand() sends data get entity Steve. Minecraft answers in three packets of 4096, 4096 and 1870 bytes, and sendCommand() returns one string of 10062 bytes that starts with Steve has the following entity data.

Usage

composer require stilling/minecraft-rcon
use Stilling\MinecraftRcon\Exceptions\RconException;
use Stilling\MinecraftRcon\Rcon;

$rcon = new Rcon("mc.example.com", 25575, "super-secret-password", timeout: 5);

try {
    $rcon->connect();
    $players = $rcon->sendCommand("list");
    // "There are 2 of a max of 20 players online: Alex, Steve"
} catch (RconException $e) {
    // Log the error or show it to the user.
} finally {
    $rcon->disconnect();
}

Details

Works well withMinecraft SNBT Parser Read the NBT data that data get returns as PHP values or typed tags.