PHP code example of innmind / server-control

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

    

innmind / server-control example snippets


use Innmind\Server\Control\{
    ServerFactory,
    Server\Command,
    Server\Process\Output\Chunk,
    Server\Process\Output\Type,
    Server\Process\Pid,
    Server\Signal,
    Server\Volumes\Name,
};
use Innmind\TimeContinuum\Clock;
use Innmind\TimeWarp\Halt\Usleep;
use Innmind\IO\IO;
use Innmind\Url\Path;
use Innmind\Immutable\Str;

$server = ServerFactory::build(
    Clock::live(),
    IO::fromAmbientAuthority(),
    Usleep::new(),
);
$server
    ->processes()
    ->execute(
        Command::foreground('bin/console')
            ->withArgument('debug:router')
    )
    ->unwrap()
    ->output()
    ->foreach(static function(Chunk $chunk): void {
        $type = match ($chunk->type()) {
            Type::error => 'ERR : ',
            Type::output => 'OUT : ',
        };

        echo $type.$chunk->data()->toString();
    });
$server
    ->processes()
    ->kill(
        new Pid(42),
        Signal::kill,
    )
    ->unwrap();
$server
    ->volumes()
    ->mount(new Name('/dev/disk2s1'), Path::of('/somewhere')) // the path is only interpreted for linux
    ->unwrap();
$server
    ->volumes()
    ->unmount(new Name('/dev/disk2s1'))
    ->unwrap();
$server->reboot()->unwrap();
$server->shutdown()->unwrap();

use Innmind\Server\Control\Server\{
    Script,
    Command,
};

$script = Script::of(
    Command::foreground('apt-get install php-fpm -y'),
    Command::foreground('service nginx start'),
);
$script($server);

use Innmind\Server\Control\Servers\Remote;
use Innmind\Url\Authority\{
    Host,
    Port,
    UserInformation\User,
};

$server = Remote::of(
    $server,
    User::of('john'),
    Host::of('example.com'),
    Port::of(42),
);
$server
    ->processes()
    ->execute(Command::foreground('ls'))
    ->unwrap();

use Innmind\Server\Control\Servers\Logger;
use Psr\Log\LoggerInterface;

$server = Logger::psr($server, /** an instance of LoggerInterface */);