MineCraft RCON via PHP

Today I went looking for examples of how to talk to a minecraft server via RCON. There is not a lot out there, and that surprised me.  I did eventually find a PHP script that worked, but it required the modification of an existing class.  I don’t like modifying someone else’s source class files to make a program work, that is why PHP has the ability to extend the class.   What follows is a simple program, that extendis the verion 1.0  rcon.class.php from http://fremnet.net/article/199/source-rcon-class and connects to a minecraft 1.2.3 server and executes the console command “say”, the result is returned in a string.   I hope this example helps others out. See the example after the break.



// Extend the rcon class to tweak it for minecraft.
class minecraftRcon extends rcon {

function mcSendCommand($Command) {

function mcRconCommand($Command) {

$ret = $this->Read();

return $ret[$this->_Id]['S1'];

// Server connection varialbes
$server = "minecraft.example.com";
$rconPort = 123456;
$rconPass = "PASSWORD";

// Connect to the server
$r = new minecraftRcon($server, $rconPort, $rconPass);

// Authenticate, and if so, execute command(s)
if ( $r->Auth() ) {

echo "Authenticatedn";

// Send a command
var_dump($r->mcRconCommand('say Hello World!'));

6 thoughts on “MineCraft RCON via PHP

  1. for me, the Auth() function needed adjustment so under ‘class minecraftRcon extends rcon {‘ just paste:

    function Auth () {
    $PackID = $this->_Write(SERVERDATA_AUTH,$this->Password);$ret = $this->_PacketRead();
    if ($ret[0][‘ID’] == -1) {die(“Authentication Failuren”);}
    return true;

Comments are closed.