Download the PHP package rikanishu/php-multi-process without Composer
On this page you can find all versions of the php package rikanishu/php-multi-process. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rikanishu/php-multi-process
More information about rikanishu/php-multi-process
Files in rikanishu/php-multi-process
Package php-multi-process
Short Description PHP library for parallel shell commands execution
License BSD-3-Clause
Informations about the package php-multi-process
php-multi-process
PHP library for parallel shell command execution
Installation via composer:
Either run
or add
to the section of your file.
Example:
Description
This library is designed to execute single / multiple parallel process on blocking / non-blocking mode. The library provides an interface for convenient configuring external process execution. The basic concepts are Pool and Command objects. Pool is a set of commands that creates and delegates execution to ExecutionContext, ExecutionContext builds Process objects for each command and runs it. Command object represents single external command.
The library uses proc_* API and select sys call that are provided by standard PHP library. It has no external dependency.
Usage
General usage scenario suggests that you pass some commands to a Pool instance which will be executed parallel on blocking / non-blocking mode depends on params passed on. Here is example of non-blocking execution of four commands:
, , , and show different format of commands applied by Pool. You can also pass instance of Command right away because Pool implicitly converts shell command text to Command instances and checks input data for this class first.
The Pool’s method returns Futures array that represents each command, e.g. represents from example above. You can always use method to get current future for executed command. Non executed command does not have Future and if you call for non-executed Command, Exception will be raised. You can call for checking when your code does not know, has command been ran or hasn't.
On non blocking mode call creates a process array and returns control to calling procedure. The process will execute at the meantime in background and when you call Future’s method, it blocks execution process until result is received or time limit is expired. You can always check Future’s if you want to avoid blocking and continue your useful calculating process.
And also if you need to run only single command you can use command method directly. It will create new Pool with single command and return Future. Use method to run execution in blocking mode and receive execution result.
Or
Pool options
Pool takes options array as second parameter. You can set some options to Pool by two ways:
-
Pass an array of options as second param to Pool construct:
- Set param after the object creating:
Options list
-
- Limit of time in seconds for execution process. Values are less than zero interpret as unlimited time out. Default is -1 (has no limits). Alias method for option is .
-
- Maximum timeout in seconds for every select poll cycle. This means time for waiting any react of running process and if it has no any react (out text to stdout / stderr or stop execution for example), retry the poll cycle after reading process status. Default value is 60 seconds. Alias method for option is .
-
- Time for poll cycle in microseconds if select call returns false or does not supported by system for proc polling (for example on Windows). Default is 200 microseconds. Alias method for option is .
-
- Debug mode. Enables some output debug messages for execution. Default is false. Alas for this method is
-
- Blocking mode flag. If blocking mode used, process will be stopped for all execution time. In other case, current process can interact with Future to wait results or check execution status. Default is false, non-blocking mode. Alias for this method is .
Command options
You can configure Command same as Pool by two ways:
Or
And also you can control options when you pass shell command to Pool construct as array second element:
Options list
-
- Environment variables list for command. Default is null. Alias method for this option is .
-
- Current working directory for command. Default is null and CWD inherits from parent process. Alias method for this option is .
-
- Options for proc_open command. See full list in PHP Documentation. Alias method for this option is .
-
- Stdin for command. Alias method for this option is .
-
- Don't wait the end of execution and don't check process state to recognize whether it runs or doesn't, just read stdin/stdout and stop process. Useful in working with pipes to stop execution process after it gives any output. Alias method for this option is .