Last change
on this file since 816 was 816, checked in by chronos, 9 years ago |
- Added: Process class for executing child processes.
|
File size:
1.1 KB
|
Line | |
---|
1 | <?php
|
---|
2 |
|
---|
3 | class Process
|
---|
4 | {
|
---|
5 | var $Command;
|
---|
6 | var $Handle;
|
---|
7 | var $Pipes;
|
---|
8 | var $Environment;
|
---|
9 | var $WorkingDir;
|
---|
10 |
|
---|
11 | function __construct()
|
---|
12 | {
|
---|
13 | $this->Command = '';
|
---|
14 | $this->Handle = null;
|
---|
15 | $this->Pipes = array();
|
---|
16 | $this->Environment = array();
|
---|
17 | $this->WorkingDir = null;
|
---|
18 | }
|
---|
19 |
|
---|
20 | function Start()
|
---|
21 | {
|
---|
22 | if(!$this->IsRunning())
|
---|
23 | {
|
---|
24 | $DescriptorSpec = array(
|
---|
25 | 0 => array("pipe", "r"), // stdin is a pipe that the child will read from
|
---|
26 | 1 => array("pipe", "w"), // stdout is a pipe that the child will write to
|
---|
27 | 2 => array("pipe", "w") // stderr is a pipe that the child will write to
|
---|
28 | );
|
---|
29 |
|
---|
30 | $this->Handle = proc_open($this->Command, $DescriptorSpec, $this->Pipes,
|
---|
31 | $this->WorkingDir, $this->Environment);
|
---|
32 | stream_set_blocking($this->Pipes[0], FALSE);
|
---|
33 | stream_set_blocking($this->Pipes[1], FALSE);
|
---|
34 | stream_set_blocking($this->Pipes[2], FALSE);
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | function Stop()
|
---|
39 | {
|
---|
40 | if($this->IsRunning())
|
---|
41 | {
|
---|
42 | proc_close($this->Handle);
|
---|
43 | $this->Handle = null;
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | function IsRunning()
|
---|
48 | {
|
---|
49 | return(is_resource($this->Handle));
|
---|
50 | }
|
---|
51 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.