These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* (c) Anton Medvedev <[email protected]> |
||
3 | * |
||
4 | * For the full copyright and license information, please view the LICENSE |
||
5 | * file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | namespace Deployer\Utility; |
||
9 | |||
10 | /** |
||
11 | * @codeCoverageIgnore |
||
12 | */ |
||
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 | if (extension_loaded('pcntl')) { |
||
21 | declare(ticks = 1); |
||
22 | $pid = pcntl_fork(); |
||
23 | } |
||
24 | |||
25 | if (is_null($pid) || $pid === -1) { |
||
26 | // Fork fails or there is no `pcntl` extension. |
||
27 | try { |
||
28 | self::send($stats); |
||
29 | } catch (\Throwable $e) { |
||
30 | // pass |
||
31 | } |
||
32 | } elseif ($pid === 0) { |
||
33 | // Child process. |
||
34 | posix_setsid(); |
||
35 | try { |
||
36 | self::send($stats); |
||
37 | } catch (\Throwable $e) { |
||
38 | // pass |
||
39 | } |
||
40 | // Close child process after doing job. |
||
41 | exit(0); |
||
0 ignored issues
–
show
|
|||
42 | } |
||
43 | } |
||
44 | |||
45 | private static function send(array $stats) |
||
46 | { |
||
47 | Httpie::post(self::ENDPOINT) |
||
48 | ->body($stats) |
||
49 | ->setopt(CURLOPT_SSL_VERIFYPEER, false) |
||
50 | ->send(); |
||
51 | } |
||
52 | } |
||
53 |
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.