Total Complexity | 9 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class Reporter |
||
14 | { |
||
15 | const ENDPOINT = 'https://deployer.org/api/stats'; |
||
16 | |||
17 | public static function report(array $stats) |
||
18 | { |
||
19 | $pid = null; |
||
20 | // make sure function is not disabled via php.ini "disable_functions" |
||
21 | if (extension_loaded('pcntl') && function_exists('pcntl_fork')) { |
||
22 | declare(ticks = 1); |
||
23 | $pid = pcntl_fork(); |
||
24 | } |
||
25 | |||
26 | if (is_null($pid) || $pid === -1) { |
||
27 | // Fork fails or there is no `pcntl` extension. |
||
28 | try { |
||
29 | self::send($stats); |
||
30 | } catch (\Throwable $e) { |
||
31 | // pass |
||
32 | } |
||
33 | } elseif ($pid === 0) { |
||
34 | // Child process. |
||
35 | posix_setsid(); |
||
36 | try { |
||
37 | self::send($stats); |
||
38 | } catch (\Throwable $e) { |
||
39 | // pass |
||
40 | } |
||
41 | // Close child process after doing job. |
||
42 | exit(0); |
||
|
|||
43 | } |
||
44 | } |
||
45 | |||
46 | private static function send(array $stats) |
||
52 | } |
||
53 | } |
||
54 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.