PHP code example of anvilm / php.rcon

1. Go to this page and download the library: Download anvilm/php.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/ */

    

anvilm / php.rcon example snippets


use AnvilM\RCON\Clients\Minecraft\MinecraftClient;

$Ip = '127.0.0.1'; //Server IP
$Port = 25575; //RCON port

$Client = new MinecraftClient($Ip, $Port);

$Password = '123' // RCON Password

$Client->authenticate($Password);

$Client->sendCommand('time set day');

use AnvilM\RCON\Entity\RCON

$data = new RCON(
    1, // packet id, the response will have the same id
    2 // packet type, may vary by implementation
    'time set day' // command 
);

use AnvilM\RCON\RCONClient;
use AnvilM\RCON\Entity\RCON;

$client = new RCONClient('127.0.0.1', 25575);

// Minecraft authorization
$data = new RCON(1, 3, '123');

// Returns new RCON(1, 2, '')
$response = $client->request($data);

use AnvilM\RCON\RCONClient;

$client = new RCONClient('127.0.0.1', 25575);

$connection = $client->getConnection();

// Close connection and create new socket
$connection->close();

// Open connection with new socket
$connection->open()

// Auth with new socket
$client->request(
    new RCON(1, 3, '123')
);

bash
composer