|
15 | 15 | /** |
16 | 16 | * Process component. |
17 | 17 | * |
18 | | - * This class borrows logic from Symfony's Process component for ensuring |
19 | | - * compatibility when PHP is compiled with the --enable-sigchild option. |
20 | | - * |
21 | 18 | * This class also implements the `EventEmitterInterface` |
22 | 19 | * which allows you to react to certain events: |
23 | 20 | * |
|
40 | 37 | * ``` |
41 | 38 | * |
42 | 39 | * Note that `$code` is `null` if the process has terminated, but the exit |
43 | | - * code could not be determined (for example |
44 | | - * [sigchild compatibility](#sigchild-compatibility) was disabled). |
| 40 | + * code could not be determined. |
45 | 41 | * Similarly, `$term` is `null` unless the process has terminated in response to |
46 | 42 | * an uncaught signal sent to it. |
47 | 43 | * This is not a limitation of this project, but actual how exit codes and signals |
@@ -91,18 +87,13 @@ class Process extends EventEmitter |
91 | 87 | private $env; |
92 | 88 | private $fds; |
93 | 89 |
|
94 | | - private $enhanceSigchildCompatibility; |
95 | | - private $sigchildPipe; |
96 | | - |
97 | 90 | private $process; |
98 | 91 | private $status; |
99 | 92 | private $exitCode; |
100 | 93 | private $fallbackExitCode; |
101 | 94 | private $stopSignal; |
102 | 95 | private $termSignal; |
103 | 96 |
|
104 | | - private static $sigchild; |
105 | | - |
106 | 97 | /** |
107 | 98 | * Constructor. |
108 | 99 | * |
@@ -145,7 +136,6 @@ public function __construct($cmd, $cwd = null, array $env = null, array $fds = n |
145 | 136 | } |
146 | 137 |
|
147 | 138 | $this->fds = $fds; |
148 | | - $this->enhanceSigchildCompatibility = self::isSigchildEnabled(); |
149 | 139 | } |
150 | 140 |
|
151 | 141 | /** |
@@ -173,23 +163,6 @@ public function start(LoopInterface $loop = null, $interval = 0.1) |
173 | 163 | $loop = $loop ?: Loop::get(); |
174 | 164 | $cmd = $this->cmd; |
175 | 165 | $fdSpec = $this->fds; |
176 | | - $sigchild = null; |
177 | | - |
178 | | - // Read exit code through fourth pipe to work around --enable-sigchild |
179 | | - if ($this->enhanceSigchildCompatibility) { |
180 | | - $fdSpec[] = array('pipe', 'w'); |
181 | | - \end($fdSpec); |
182 | | - $sigchild = \key($fdSpec); |
183 | | - |
184 | | - // make sure this is fourth or higher (do not mess with STDIO) |
185 | | - if ($sigchild < 3) { |
186 | | - $fdSpec[3] = $fdSpec[$sigchild]; |
187 | | - unset($fdSpec[$sigchild]); |
188 | | - $sigchild = 3; |
189 | | - } |
190 | | - |
191 | | - $cmd = \sprintf('(%s) ' . $sigchild . '>/dev/null; code=$?; echo $code >&' . $sigchild . '; exit $code', $cmd); |
192 | | - } |
193 | 166 |
|
194 | 167 | // on Windows, we do not launch the given command line in a shell (cmd.exe) by default and omit any error dialogs |
195 | 168 | // the cmd.exe shell can explicitly be given as part of the command as detailed in both documentation and tests |
@@ -242,11 +215,6 @@ public function start(LoopInterface $loop = null, $interval = 0.1) |
242 | 215 | }); |
243 | 216 | }; |
244 | 217 |
|
245 | | - if ($sigchild !== null) { |
246 | | - $this->sigchildPipe = $pipes[$sigchild]; |
247 | | - unset($pipes[$sigchild]); |
248 | | - } |
249 | | - |
250 | 218 | foreach ($pipes as $n => $fd) { |
251 | 219 | // use open mode from stream meta data or fall back to pipe open mode for legacy HHVM |
252 | 220 | $meta = \stream_get_meta_data($fd); |
@@ -292,11 +260,6 @@ public function close() |
292 | 260 | $pipe->close(); |
293 | 261 | } |
294 | 262 |
|
295 | | - if ($this->enhanceSigchildCompatibility) { |
296 | | - $this->pollExitCodePipe(); |
297 | | - $this->closeExitCodePipe(); |
298 | | - } |
299 | | - |
300 | 263 | $exitCode = \proc_close($this->process); |
301 | 264 | $this->process = null; |
302 | 265 |
|
@@ -350,7 +313,7 @@ public function getCommand() |
350 | 313 | * will be returned if the process is still running. |
351 | 314 | * |
352 | 315 | * Null may also be returned if the process has terminated, but the exit |
353 | | - * code could not be determined (e.g. sigchild compatibility was disabled). |
| 316 | + * code could not be determined. |
354 | 317 | * |
355 | 318 | * @return int|null |
356 | 319 | */ |
@@ -437,85 +400,6 @@ public function isTerminated() |
437 | 400 | return $status !== null ? $status['signaled'] : false; |
438 | 401 | } |
439 | 402 |
|
440 | | - /** |
441 | | - * Return whether PHP has been compiled with the '--enable-sigchild' option. |
442 | | - * |
443 | | - * @see \Symfony\Component\Process\Process::isSigchildEnabled() |
444 | | - * @return bool |
445 | | - */ |
446 | | - public final static function isSigchildEnabled() |
447 | | - { |
448 | | - if (null !== self::$sigchild) { |
449 | | - return self::$sigchild; |
450 | | - } |
451 | | - |
452 | | - if (!\function_exists('phpinfo')) { |
453 | | - return self::$sigchild = false; // @codeCoverageIgnore |
454 | | - } |
455 | | - |
456 | | - \ob_start(); |
457 | | - \phpinfo(INFO_GENERAL); |
458 | | - |
459 | | - return self::$sigchild = false !== \strpos(\ob_get_clean(), '--enable-sigchild'); |
460 | | - } |
461 | | - |
462 | | - /** |
463 | | - * Enable or disable sigchild compatibility mode. |
464 | | - * |
465 | | - * Sigchild compatibility mode is required to get the exit code and |
466 | | - * determine the success of a process when PHP has been compiled with |
467 | | - * the --enable-sigchild option. |
468 | | - * |
469 | | - * @param bool $sigchild |
470 | | - * @return void |
471 | | - */ |
472 | | - public final static function setSigchildEnabled($sigchild) |
473 | | - { |
474 | | - self::$sigchild = (bool) $sigchild; |
475 | | - } |
476 | | - |
477 | | - /** |
478 | | - * Check the fourth pipe for an exit code. |
479 | | - * |
480 | | - * This should only be used if --enable-sigchild compatibility was enabled. |
481 | | - */ |
482 | | - private function pollExitCodePipe() |
483 | | - { |
484 | | - if ($this->sigchildPipe === null) { |
485 | | - return; |
486 | | - } |
487 | | - |
488 | | - $r = array($this->sigchildPipe); |
489 | | - $w = $e = null; |
490 | | - |
491 | | - $n = @\stream_select($r, $w, $e, 0); |
492 | | - |
493 | | - if (1 !== $n) { |
494 | | - return; |
495 | | - } |
496 | | - |
497 | | - $data = \fread($r[0], 8192); |
498 | | - |
499 | | - if (\strlen($data) > 0) { |
500 | | - $this->fallbackExitCode = (int) $data; |
501 | | - } |
502 | | - } |
503 | | - |
504 | | - /** |
505 | | - * Close the fourth pipe used to relay an exit code. |
506 | | - * |
507 | | - * This should only be used if --enable-sigchild compatibility was enabled. |
508 | | - */ |
509 | | - private function closeExitCodePipe() |
510 | | - { |
511 | | - if ($this->sigchildPipe === null) { |
512 | | - return; |
513 | | - } |
514 | | - |
515 | | - \fclose($this->sigchildPipe); |
516 | | - $this->sigchildPipe = null; |
517 | | - } |
518 | | - |
519 | 403 | /** |
520 | 404 | * Return the cached process status. |
521 | 405 | * |
|
0 commit comments