2017 © Pedro Peláez
 

library php-shell

image

azurre/php-shell

  • Saturday, March 31, 2018
  • by a.milenin
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

PHP Shell Latest Version

This small and easy to use PHP shell make it able to run commands as non blocking asynchronous jobs, (*1)

Installation

Install composer in your project:, (*2)

curl -s https://getcomposer.org/installer | php

Require the package with composer:, (*3)

composer require azurre/php-shell

Usage

Simple example

$loader = require_once __DIR__ . '/vendor/autoload.php';

use Azurre\Component\System\Shell;

$cmd = 'ls -lwa /tmp';
echo Shell::create()->run($cmd);

Output, (*4)

total 180
drwxrwxrwt 11 root     root     4096 Jul  4 23:21 .
drwxr-xr-x 22 root     root     4096 Jun 10 16:23 ..
drwxrwxrwt  2 root     root     4096 Jun 10 16:23 .ICE-unix
drwxrwxrwt  2 root     root     4096 Jun 10 16:23 .X11-unix
drwxrwxrwt  2 root     root     4096 Jun 10 16:23 .XIM-unix
drwxrwxrwt  2 root     root     4096 Jun 10 16:23 .font-unix
-rw-------  1 www-data www-data    0 Jul  1 21:21 239315d1a4f341c8b52.14168329mUCCHL
-rw-r--r--  1 www-data www-data 6468 Jul  1 21:18 416205d1a4e5fe8e166.51692428EFpYWQ
-rw-r--r--  1 www-data www-data 6469 Jul  1 21:21 443675d1a4f3ce6efd0.08860101uETZWS
-rw-r--r--  1 www-data www-data 6416 Jul  1 21:26 494485d1a503c71cfd8.3817705715MVk4
-rw-r--r--  1 www-data www-data 6468 Jul  1 21:19 519335d1a4eba5a2ef8.14398347CWkGkb
-rw-------  1 www-data www-data    0 Jul  1 21:27 575735d1a508060a080.18275551cZg15T

Background tasks

$shell = new Shell;
$shell->runAsync('ping -c 5 127.0.0.1');

echo "Start background task\n";
while($shell->isProcessRunning()) {
    echo 'Working...' .PHP_EOL;
    sleep(1);
}
echo $shell;

Output, (*5)

Start background task
Working...
Working...
Working...
Working...
Working...
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.020 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.022 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.015 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms
64 bytes from 127.0.0.1: icmp_seq=5 ttl=64 time=0.019 ms

--- 127.0.0.1 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4099ms
rtt min/avg/max/mdev = 0.015/0.019/0.023/0.006 ms

Error handling

$shell = new Shell;
$shell->run('ls /A/1/2/3/4')->waitForProcess();
if ($shell->getExitCode() !== Shell::NO_ERROR) {
    echo "\nExit code: {$shell->getExitCode()}\n";
    echo "Error: {$shell->getStdError()}\n";
} else {
    echo $shell->getStdOut();
}

Output, (*6)

Exit code: 2
Error: ls: cannot access '/A/1/2/3/4': No such file or directory

License

MIT, (*7)

The Versions

31/03 2018

v1.0

1.0.0.0

  Sources   Download

20/03 2017

dev-master

9999999-dev https://github.com/azurre/php-shell

A convenient component of PHP CLI wrapper

  Sources   Download

MIT

by Aleksandr Milenin

process shell linux cmd

20/03 2017

v1.2

1.2.0.0 https://github.com/azurre/php-shell

A convenient component of PHP CLI wrapper

  Sources   Download

MIT

by Aleksandr Milenin

process shell linux cmd

20/03 2017

dev-dev

dev-dev https://github.com/azurre/php-shell

A convenient component of PHP CLI wrapper

  Sources   Download

MIT

by Aleksandr Milenin

process shell linux cmd

11/03 2017

v1.1

1.1.0.0 https://github.com/azurre/php-shell

A convenient component of PHP CLI wrapper

  Sources   Download

MIT

by Aleksandr Milenin

process shell linux cmd