innmind / server-control
Allows to control the server from php
6.0.0
2025-04-21 16:24 UTC
Requires
- php: ~8.2
- innmind/filesystem: ~8.0
- innmind/immutable: ~5.12
- innmind/io: ~3.1
- innmind/time-continuum: ^4.1.1
- innmind/time-warp: ~4.0
- innmind/url: ~4.0
- psr/log: ~3.0
Requires (Dev)
- innmind/black-box: ~6.1
- innmind/coding-standard: ~2.0
- innmind/static-analysis: ^1.2.1
- dev-develop
- 6.0.0
- 5.2.3
- 5.2.2
- 5.2.1
- 5.2.0
- 5.1.0
- 5.0.0
- 4.3.0
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.3.0
- 3.2.0
- 3.1.0
- 3.0.1
- 3.0.0
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.0
- 2.1.0
- 2.0.0
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.0
- dev-master
- dev-more-precise-timeouts
- dev-protect-internals
- dev-attempt
- dev-cs
- dev-update-dependencies
- dev-reuse-workflows
- dev-remove-phpunit
- dev-final-process
- dev-simplify-process-output
- dev-static-analysis
- dev-blackbox-6
- dev-license-date-range
- dev-fix-php-84-deprecations
This package is auto-updated.
Last update: 2025-04-21 16:25:45 UTC
README
Give access to giving instructions to the server.
Important
To correctly use this library you must validate your code with vimeo/psalm
Installation
composer require innmind/server-control
Usage
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();
Scripts
Sometimes you may want to run a set of commands on your server. You can easily do so like this:
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);
If any command fails, it will stop the script and raise an exception.
Remote server control
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();
This will run ssh -p 42 john@example.com ls
.
Important
Specifying environment variables or an input stream will not be taken into account on the remote server.
Logging
use Innmind\Server\Control\Servers\Logger; use Psr\Log\LoggerInterface; $server = Logger::psr($server, /** an instance of LoggerInterface */);