InterExec
in package
Interactive process execution helper.
Included for historical compatibility only. This API is out of support and should not be used in new code.
Tags
Table of Contents
Constants
- PIPE_TYPE_DEFAULT : mixed = 'pipe'
- PIPE_TYPE_PTY : mixed = 'pty'
- STDERR : mixed = 2
- STDIN : mixed = 0
- STDOUT : mixed = 1
Properties
- $command_to_run : string
- The command to run.
- $data_buffer_size : int
- Size of buffer for reading from pipes.
- $environment_vars : array<string|int, mixed>|null
- Environment variables (null to use existing variables).
- $fix_windows_path : bool
- If enabled, fixes a problem with popen not allowing spaces inside program path (even when quoted).
- $pipes : array<string|int, mixed>
- Process I/O pipes.
- $pipeType : string
- Pipe type, pipe or pty (Linux only, PHP must be compiled with --enable-pty) Constants : PIPE_TYPE_DEFAULT, PIPE_TYPE_PTY
- $process_handle : resource
- Process resource.
- $return : int
- Program's exit code (obviously only set after program quits).
- $stderr : string
- All of the program's error output till now.
- $stdout : string
- All of the program's standard output till now.
- $taken : float
- Legacy timeout counter name used by the original implementation.
- $tick_interval : float
- Interval between ticks, in seconds (a value of zero disables interval)
- $time_start : float
- Timestamp in seconds of start of execution.
- $time_taken : float
- The time taken for the program to run and close.
- $timeout : int
- Time, in seconds, after which command is forcefully aborted.
- $events : array<string|int, mixed>
- Array containing event callbacks.
Methods
- __construct() : mixed
- Creates new instance.
- is_running() : bool
- Returns whether process is currently running or not.
- on() : mixed
- Call callback when an event is triggered.
- run() : InterExec
- Runs the command!
- fire() : mixed
- Trigger an event.
- fix_windows_command_path() : string
- This hack fixes a legacy issue in popen not handling escaped command filenames on Windows.
- run_mainloop() : mixed
- run_shutdown() : mixed
- run_startup() : mixed
- stream_has_content() : bool
- Returns whether stream currently has pending content or not.
Constants
PIPE_TYPE_DEFAULT
public
mixed
PIPE_TYPE_DEFAULT
= 'pipe'
PIPE_TYPE_PTY
public
mixed
PIPE_TYPE_PTY
= 'pty'
STDERR
public
mixed
STDERR
= 2
STDIN
public
mixed
STDIN
= 0
STDOUT
public
mixed
STDOUT
= 1
Properties
$command_to_run
The command to run.
public
string
$command_to_run
= ''
$data_buffer_size
Size of buffer for reading from pipes.
public
int
$data_buffer_size
= 4096
$environment_vars
Environment variables (null to use existing variables).
public
array<string|int, mixed>|null
$environment_vars
= null
$fix_windows_path
If enabled, fixes a problem with popen not allowing spaces inside program path (even when quoted).
public
bool
$fix_windows_path
= true
$pipes
Process I/O pipes.
public
array<string|int, mixed>
$pipes
= null
$pipeType
Pipe type, pipe or pty (Linux only, PHP must be compiled with --enable-pty) Constants : PIPE_TYPE_DEFAULT, PIPE_TYPE_PTY
public
string
$pipeType
= self::PIPE_TYPE_DEFAULT
$process_handle
Process resource.
public
resource
$process_handle
= null
$return
Program's exit code (obviously only set after program quits).
public
int
$return
= 0
$stderr
All of the program's error output till now.
public
string
$stderr
= ''
$stdout
All of the program's standard output till now.
public
string
$stdout
= ''
$taken
Legacy timeout counter name used by the original implementation.
public
float
$taken
= 0
$tick_interval
Interval between ticks, in seconds (a value of zero disables interval)
public
float
$tick_interval
= 0
$time_start
Timestamp in seconds of start of execution.
public
float
$time_start
= 0.0
$time_taken
The time taken for the program to run and close.
public
float
$time_taken
= 0
$timeout
Time, in seconds, after which command is forcefully aborted.
public
int
$timeout
= 0
$events
Array containing event callbacks.
protected
array<string|int, mixed>
$events
= array()
Methods
__construct()
Creates new instance.
public
__construct(string $command_to_run[, array<string|int, mixed> $environment_vars = null ]) : mixed
Parameters
- $command_to_run : string
-
The command line to execute.
- $environment_vars : array<string|int, mixed> = null
-
(Optional) Environment variables.
is_running()
Returns whether process is currently running or not.
public
is_running() : bool
Return values
boolon()
Call callback when an event is triggered.
public
on(string $event, callable $callback) : mixed
Parameters
- $event : string
-
Name of event.
- $callback : callable
-
The callback to call.
run()
Runs the command!
public
run() : InterExec
Return values
InterExecfire()
Trigger an event.
protected
fire(string $event[, array<string|int, mixed> $args = array() ]) : mixed
Parameters
- $event : string
-
Name of event.
- $args : array<string|int, mixed> = array()
-
(Optional) Arguments to pass to event. Note that the first argument is always $this.
Return values
mixed —Value resulting from event callback.
fix_windows_command_path()
This hack fixes a legacy issue in popen not handling escaped command filenames on Windows.
protected
fix_windows_command_path(string $commandPath) : string
Basically, if we're on windows and the first command part is double quoted, we CD into the directory and execute the command from there.
Parameters
- $commandPath : string
-
The command to fix.
Tags
Return values
string —The command with the path fixed.
run_mainloop()
protected
run_mainloop() : mixed
run_shutdown()
protected
run_shutdown() : mixed
run_startup()
protected
run_startup() : mixed
stream_has_content()
Returns whether stream currently has pending content or not.
protected
stream_has_content(resource $stream) : bool
Parameters
- $stream : resource
-
The stream resource.
Return values
bool —True if there is unread content, false otherwise.