PHP code example of dev-lancer / minecraft-rcon

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

    

dev-lancer / minecraft-rcon example snippets


$host = 'some.minecraftserver.com'; // Server host name or IP
$port = 25575;                      // Port rcon is listening on
$password = 'server-rcon-password'; // rcon.password setting set in server.properties
$timeout = 3;                       // How long to timeout.

use DevLancer\MinecraftRcon;

$rcon = new Rcon($host, $port, $password, $timeout);

if ($rcon->connect()) {
    if ($rcon->sendCommand("say Hello World!") === false) {
        //bad request
    } else {
        echo $rcon->getResponse(); //success
    }
} else {
    echo $rcon->getResponse(); //error
}