clue / shell-react
Run async commands within any interactive shell command, built on top of ReactPHP.
Fund package maintenance!
clue
clue.engineering/support
Installs: 1 278
Dependents: 1
Suggesters: 0
Security: 0
Stars: 33
Watchers: 6
Forks: 14
Open Issues: 5
Requires
- php: >=5.3
- react/child-process: ~0.3.0|~0.4.0
- react/event-loop: ~0.3.0|~0.4.0
- react/promise: ~1.0|~2.0
- react/stream: ~0.3.0|~0.4.0
This package is auto-updated.
Last update: 2024-10-11 11:39:20 UTC
README
Run async commands within any interactive shell command, built on top of ReactPHP.
Note: This project is in beta stage! Feel free to report any issues you encounter.
Quickstart example
Once installed, you can use the following code to run an interactive bash shell and issue some commands within:
<?php require __DIR__ . '/vendor/autoload.php'; $launcher = new Clue\React\Shell\ProcessLauncher(); $shell = $launcher->createDeferredShell('bash'); $shell->execute('echo -n $USER')->then(function ($result) { var_dump('current user', $result); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->execute('env | sort | head -n10')->then(function ($env) { var_dump('env', $env); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); $shell->end();
See also the examples:
- Run shell commands within a bash shell
- Run PHP code within an interactive PHP shell
- Run shell commands within a docker container
Install
The recommended way to install this library is through Composer. New to Composer?
This will install the latest supported version:
composer require clue/shell-react:^0.2
See also the CHANGELOG for details about version upgrades.
This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 8+. It's highly recommended to use the latest supported PHP version for this project.
Tests
To run the test suite, you first need to clone this repo and then install all dependencies through Composer:
composer install
To run the test suite, go to the project root and run:
vendor/bin/phpunit
License
MIT