php-scripts
This librairy provides utilities function to ease scripts manipulation, (*1)
, (*2)
Install
Install package with composer, (*3)
composer require hugsbrugs/php-scripts
In your PHP code, load library, (*4)
require_once __DIR__ . '/../vendor/autoload.php';
use Hug\Scripts\Scripts as Scripts;
Usage
Run a script, output is saved to log file, (*5)
$cmd = 'ls -lsa';
$log_file = __DIR__ . '/test.log';
$res = Scripts::run($cmd, $log_file);
Outputs, (*6)
[status] => success
[message] =>
[data] => Array
(
[pid] => 3358
[log] => /path/to/test.log
)
And file /path/to/test.log contains output of ls -lsa command, (*7)
Checks if a script is running, (*8)
$running = Scripts::is_running($res['data']['pid']);
Get Memory and processor usage for a script, (*9)
$cpu_mem = Scripts::get_pid_cpu_mem($res['data']['pid']);
outputs, (*10)
[mem] => 0.2
[cpu] => 0.1
Unit Tests
composer exec phpunit
Author
Hugo Maugey visit my website ;), (*11)