1 | <?php |
||
11 | class Process implements ProcessInterface |
||
12 | { |
||
13 | /** |
||
14 | * process status,running |
||
15 | * @var string |
||
16 | */ |
||
17 | const STATUS_RUNNING = 'running'; |
||
18 | |||
19 | /** |
||
20 | * process status,terminated |
||
21 | * @var string |
||
22 | */ |
||
23 | const STATUS_TERMINATED = 'terminated'; |
||
24 | |||
25 | /** |
||
26 | * callback |
||
27 | * @var callable |
||
28 | */ |
||
29 | protected $callback; |
||
30 | |||
31 | /** |
||
32 | * pid |
||
33 | * @var int |
||
34 | */ |
||
35 | protected $pid; |
||
36 | |||
37 | /** |
||
38 | * Whether the process is running |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected $isRunning = false; |
||
42 | |||
43 | /** |
||
44 | * signal handler |
||
45 | * @var SignalHandler |
||
46 | */ |
||
47 | protected $signalHandler; |
||
48 | |||
49 | /** |
||
50 | * current status |
||
51 | * @var Status |
||
52 | */ |
||
53 | protected $status; |
||
54 | |||
55 | public function __construct($callback) |
||
66 | |||
67 | /** |
||
68 | * Checks whether the current environment supports this |
||
69 | * @return bool |
||
70 | */ |
||
71 | public static function isSupported() |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | public function start() |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function wait() |
||
110 | |||
111 | /** |
||
112 | * Start and wait for the process to complete |
||
113 | */ |
||
114 | public function run() |
||
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | public function stop($signal = SIGKILL) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function getPid() |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function signal($signal) |
||
147 | |||
148 | /** |
||
149 | * {@inheritdoc} |
||
150 | */ |
||
151 | public function isRunning() |
||
161 | |||
162 | /** |
||
163 | * Gets the signal handler |
||
164 | * @return SignalHandler |
||
165 | */ |
||
166 | public function getSignalHandler() |
||
170 | |||
171 | /** |
||
172 | * Gets the exit code of the process |
||
173 | * @return int |
||
174 | */ |
||
175 | public function getExitCode() |
||
179 | |||
180 | /** |
||
181 | * Updates the status of the process |
||
182 | * @param bool $blocking |
||
183 | * @throws RuntimeException |
||
184 | */ |
||
185 | protected function updateStatus($blocking = false) |
||
203 | |||
204 | /** |
||
205 | * Gets the status of the process |
||
206 | * @return Status |
||
207 | */ |
||
208 | public function getStatus() |
||
212 | } |
||
213 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.