PHP code example of anvilm / rcon

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


use AnvilM\RCON\RCON;

$Ip = '127.0.0.1'; //Server IP
$Port = 25575; //RCON port
$Password = '123'; //RCON password
$Timeout = 30; //Timeout in ms 

$RCON = new RCON($Ip, $Port, $Password, $Timeout);

use AnvilM\RCON\RCON;

...

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

use AnvilM\RCON\RCON;

...

$Response = $RCON->ResponseService->getAllResponses();

use AnvilM\RCON\RCON;

...

$Response = $RCON->ResponseService->getLastResponse();

use AnvilM\RCON\RCON;

...

$Response = $RCON->ResponseService->getResponse(3);

namespace App\Http\Controllers;

use AnvilM\RCON\RCON;

class RCONController extends Controller
{
    public function setDay()
    {
        $Ip = '127.0.0.1'; //Server IP
        $Port = 25575; //RCON port
        $Password = '123'; //RCON password
        $Timeout = 30; //Timeout in ms 

        $RCON = new RCON($Ip, $Port, $Password, $Timeout); //Create connection

        $RCON->sendCommand('time set day'); //Send command

        $Response = $RCON->ResponseService->getLastResponse(); //Get last response

        echo $Response;
    }
}