marando/process

A PHP package for managing external executable processes.

1.0 2016-08-19 05:44 UTC

This package is not auto-updated.

Last update: 2024-05-03 18:09:06 UTC


README

Process is a PHP package for managing external executable processes.

Installation

With Composer

$ composer require marando/process

Usage

Initializing a New Process

New processes can be initialized by passing the process you wish to run to the first argument of the constructor:

$proc = new Process('ping google.com');

Starting a Process

The process will not start until you call the start() method:

$proc = new Process('ping google.com');
$proc->start();

Killing a Process

If you wish to prematurely kill a process use the kill() method:

$proc = new Process('ping google.com');
$proc->start();
$proc->kill();

Status of a Process

You can check if a process is currently running by using the isRunning() method:

$proc = new Process('ping google.com');
$proc->start();
$proc->isRunning();

Getting the PID

If you need to know the PID of the process, use the pid property:

$proc = new Process('ping google.com');
$proc->start();
$proc->pid;

Waiting for Completion

The wait() method will hold up code execution until the process has completed:

$proc = new Process('ping google.com');
$proc->start();
$proc->wait();

Process Output

You can also get the output of the process from the log property, which will return a PHP SplFileObject instance that contains the output of the process. To enable this behavior you must first pass the path of the desired output file to the constructor:

$proc = new Process('ping google.com', 'logfile.log');
$proc->start();
$proc->wait();

// Echo first 100 characters of the output.
echo $proc->log->fread(100);