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.
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
A command can be at most 1446 bytes. The client throws a PacketException for a longer command and does not send it.
isConnected() tells you if the connection is still usable.