dev-lancer/server-controller

This package is abandoned and no longer maintained. No replacement package was suggested.

v1.0-stable 2021-04-13 15:26 UTC

This package is not auto-updated.

Last update: 2024-07-22 14:30:36 UTC


README

Installation

This library can installed by issuing the following command:

composer require dev-lancer/server-controller

Example

Terminal

<?php declare(strict_types=1);

use DevLancer\ServerController\Terminal;
use phpseclib3\Net\SSH2;

require_once ("vendor/autoload.php");

$host = ""; //ssh host
$login = ""; //ssh login
$password = ""; //ssh password

$ssh = new SSH2($host);
$ssh->login($login, $password);
$terminal = new Terminal($ssh, $password);

ServerControl

For minecraft server

<?php declare(strict_types=1);

use DevLancer\ServerController\Terminal;
use DevLancer\ServerController\ServerControl;
use DevLancer\ServerController\Locator;
use DevLancer\ServerController\Command;
use phpseclib3\Net\SSH2;
use phpseclib3\Net\SFTP;

require_once ("vendor/autoload.php");

$host = ""; //ssh host
$login = ""; //ssh login
$password = ""; //ssh password

$ssh = new SSH2($host);
$ssh->login($login, $password);

$sftp = new SFTP($host);
$sftp->login($login, $password);

$terminal = new Terminal($ssh, $password);
$serverControl = new ServerControl($terminal);

$port = 25565; //minecraft server port
$path = "path/to/server.jar";
$params = ["-Xms2G", "-Xmx6G"];
$locator = new Locator($sftp, $path);

$result = $serverControl->start($locator, $port, Command::MINECRAFT_START, $params);
if ($result)
    echo "Server started";

ServerMonitor

<?php declare(strict_types=1);

use DevLancer\ServerController\Terminal;
use DevLancer\ServerController\ServerControl;
use DevLancer\ServerController\ServerMonitor;
use phpseclib3\Net\SSH2;

require_once ("vendor/autoload.php");

$host = ""; //ssh host
$login = ""; //ssh login
$password = ""; //ssh password

$port = 25565; //minecraft server port

$ssh = new SSH2($host);
$ssh->login($login, $password);
$terminal = new Terminal($ssh, $password);
$serverControl = new ServerControl($terminal);

$pid = $serverControl->getPid($port);

$serverMonitor = new ServerMonitor($terminal);
print_r([
   $serverMonitor->getCpuUsage($pid),
   $serverMonitor->getMemoryUsage($pid),
   $serverMonitor->getUptime($pid) 
]);

MachineMonitor

<?php declare(strict_types=1);

use DevLancer\ServerController\Terminal;
use DevLancer\ServerController\MachineMonitor;
use phpseclib3\Net\SSH2;

require_once ("vendor/autoload.php");

$host = ""; //ssh host
$login = ""; //ssh login
$password = ""; //ssh password

$ssh = new SSH2($host);
$ssh->login($login, $password);
$terminal = new Terminal($ssh, $password);

$machineMonitor = new MachineMonitor($terminal);
print_r([
   $machineMonitor->getCpuUsage(),
   $machineMonitor->getMemoryUsage(),
   $machineMonitor->getMemoryFree(),
   $machineMonitor->getMemory()
]);

License

MIT