Skip to content

Commit 7d357a7

Browse files
authored
Merge pull request #69 from CharlotteDunoisLabs/fix-docblocks
Improve documentation for exit event and minor docblock updates
2 parents 8e08e21 + 37d545c commit 7d357a7

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

src/Process.php

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,43 @@
1515
* This class borrows logic from Symfony's Process component for ensuring
1616
* compatibility when PHP is compiled with the --enable-sigchild option.
1717
*
18-
* @event exit
18+
* This class also implements the `EventEmitterInterface`
19+
* which allows you to react to certain events:
20+
*
21+
* exit event:
22+
* The `exit` event will be emitted whenever the process is no longer running.
23+
* Event listeners will receive the exit code and termination signal as two
24+
* arguments:
25+
*
26+
* ```php
27+
* $process = new Process('sleep 10');
28+
* $process->start($loop);
29+
*
30+
* $process->on('exit', function ($code, $term) {
31+
* if ($term === null) {
32+
* echo 'exit with code ' . $code . PHP_EOL;
33+
* } else {
34+
* echo 'terminated with signal ' . $term . PHP_EOL;
35+
* }
36+
* });
37+
* ```
38+
*
39+
* Note that `$code` is `null` if the process has terminated, but the exit
40+
* code could not be determined (for example
41+
* [sigchild compatibility](#sigchild-compatibility) was disabled).
42+
* Similarly, `$term` is `null` unless the process has terminated in response to
43+
* an uncaught signal sent to it.
44+
* This is not a limitation of this project, but actual how exit codes and signals
45+
* are exposed on POSIX systems, for more details see also
46+
* [here](https://unix.stackexchange.com/questions/99112/default-exit-code-when-process-is-terminated).
47+
*
48+
* It's also worth noting that process termination depends on all file descriptors
49+
* being closed beforehand.
50+
* This means that all [process pipes](#stream-properties) will emit a `close`
51+
* event before the `exit` event and that no more `data` events will arrive after
52+
* the `exit` event.
53+
* Accordingly, if either of these pipes is in a paused state (`pause()` method
54+
* or internally due to a `pipe()` call), this detection may not trigger.
1955
*/
2056
class Process extends EventEmitter
2157
{
@@ -254,7 +290,7 @@ public function close()
254290
* Terminate the process with an optional signal.
255291
*
256292
* @param int $signal Optional signal (default: SIGTERM)
257-
* @return boolean Whether the signal was sent successfully
293+
* @return bool Whether the signal was sent successfully
258294
*/
259295
public function terminate($signal = null)
260296
{
@@ -336,7 +372,7 @@ public function getTermSignal()
336372
/**
337373
* Return whether the process is still running.
338374
*
339-
* @return boolean
375+
* @return bool
340376
*/
341377
public function isRunning()
342378
{
@@ -352,7 +388,7 @@ public function isRunning()
352388
/**
353389
* Return whether the process has been stopped by a signal.
354390
*
355-
* @return boolean
391+
* @return bool
356392
*/
357393
public function isStopped()
358394
{
@@ -364,7 +400,7 @@ public function isStopped()
364400
/**
365401
* Return whether the process has been terminated by an uncaught signal.
366402
*
367-
* @return boolean
403+
* @return bool
368404
*/
369405
public function isTerminated()
370406
{
@@ -398,7 +434,7 @@ public final static function isSigchildEnabled()
398434
* determine the success of a process when PHP has been compiled with
399435
* the --enable-sigchild option.
400436
*
401-
* @param boolean $sigchild
437+
* @param bool $sigchild
402438
* @return void
403439
*/
404440
public final static function setSigchildEnabled($sigchild)

0 commit comments

Comments
 (0)