Public Member Functions | |
| __construct ($executable, $parameters) | |
| Constructor. | |
| write ($string, $finished) | |
| Writes a string into the stdin of the process. | |
| readStdout () | |
| Reads output of the process. | |
| read () | |
| Alias for readStdout(). | |
| readStderr () | |
| Reads the error pipe of this applications. | |
| terminate () | |
| Closes all open pipes and terminates the process. | |
Static Public Member Functions | |
| static | callExternalApplication ($executable, $parameters=array()) |
| Basic way to call an external application. | |
Protected Member Functions | |
| readPipe ($pipe, $throwException) | |
| Reads from specified pipe. | |
Static Protected Member Functions | |
| static | createCommand ($executable, $parameters=array()) |
| Convenience function that will create a shell command for an executable. | |
Protected Attributes | |
| $executable | |
| The name of the executable being called. | |
| $parameters | |
| Parameters to the executable. | |
| $process | |
| The process resource provided by PHP. | |
| $pipes | |
| Communication pipes. | |
| $stderrBuffer = '' | |
| A buffer containing unprocessed output of stderr. | |
All names of executables used in this class can be configured in the spunQ configuration. If on needs the application ps, for example, the spunQ configuration value spunQ.externalApplications.ps will be used as the application name, if one was provided. The executable is assumed to bed in the PATH if no such value is configured.
The static function callExternalApplication() should be completely sufficient in most cases. Instantiate this class only if you have a complex data flow with the process. Example using the bc calculator:
try { $process = new spunQ_Process('bc', array('-sq')); $process->write('1+2*sqrt(16)', false); echo $process->readStdout(); // prints 9 $process->write('1+2*sqrt(9)', true); echo $process->readStdout(); // prints 7 $process->terminate(); } catch (spunQ_ExternalApplicationFailureException $e) { // handle exception }
Definition at line 28 of file Process.class.php.
| spunQ_Process::__construct | ( | $ | executable, | |
| $ | parameters | |||
| ) |
Constructor.
| $executable | The name of the executable. | |
| $parameters | Parameters to pass to the executable. |
| spunQ_ExternalApplicationFailureException |
Definition at line 107 of file Process.class.php.
| static spunQ_Process::callExternalApplication | ( | $ | executable, | |
| $ | parameters = array() | |||
| ) | [static] |
Basic way to call an external application.
| $executable | The name of the executable. | |
| $parameters | Parameters to pass to the executable. |
implode("\n", $returnValue) will reconstruct the output string. | spunQ_ExternalApplicationFailureException |
Definition at line 40 of file Process.class.php.
| static spunQ_Process::createCommand | ( | $ | executable, | |
| $ | parameters = array() | |||
| ) | [static, protected] |
Convenience function that will create a shell command for an executable.
| $executable | The name of the executable. | |
| $parameters | Parameters to pass to the executable. |
'safe' means that the command will be called with the given arguments. Using external applications is still prone to many attack vectors. Definition at line 60 of file Process.class.php.
| spunQ_Process::readPipe | ( | $ | pipe, | |
| $ | throwException | |||
| ) | [protected] |
Reads from specified pipe.
This function will block until there is something to read.
| $pipe | The pipe to read from | |
| $throwException | Whether to throw exceptions in case of an error. |
Definition at line 196 of file Process.class.php.
| spunQ_Process::readStderr | ( | ) |
Reads the error pipe of this applications.
Definition at line 168 of file Process.class.php.
| spunQ_Process::readStdout | ( | ) |
Reads output of the process.
| spunQ_ExternalApplicationFailureException |
Definition at line 153 of file Process.class.php.
| spunQ_Process::terminate | ( | ) |
Closes all open pipes and terminates the process.
Definition at line 179 of file Process.class.php.
| spunQ_Process::write | ( | $ | string, | |
| $ | finished | |||
| ) |
Writes a string into the stdin of the process.
| $string | The string to write. | |
| $finished | Whether there will be no more write operations on this process. If this is set to true, the stdin pipe will be closed. This is necessary for many executables to start operation. |
| spunQ_ExternalApplicationFailureException |
Definition at line 132 of file Process.class.php.
spunQ_Process::$executable [protected] |
The name of the executable being called.
Definition at line 69 of file Process.class.php.
spunQ_Process::$parameters [protected] |
spunQ_Process::$pipes [protected] |
Communication pipes.
These contain stdin[0], stdout[1] and stderr[2] pipes to the process at given indexes. Any closed pipe will be replaced by NULL.
Definition at line 89 of file Process.class.php.
spunQ_Process::$process [protected] |
The process resource provided by PHP.
Definition at line 81 of file Process.class.php.
spunQ_Process::$stderrBuffer = '' [protected] |
A buffer containing unprocessed output of stderr.
The class tries to provide hints as to why an operation failed and will read the stderr pipe arbitrarily. In order to be able to provide the contents on demand, they will be buffered here. Have a look at the implementation of write() and readStderr(), if this confuses you.
Definition at line 99 of file Process.class.php.
1.5.9