1 | <?php |
||
2 | |||
3 | declare(ticks=1); |
||
4 | declare(strict_types=1); |
||
5 | |||
6 | error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
||
7 | |||
8 | /* Remove the execution time limit */ |
||
9 | set_time_limit(0); |
||
10 | |||
11 | /* Set default time to UTC */ |
||
12 | date_default_timezone_set('UTC'); |
||
13 | |||
14 | $startMicrotime = microtime(true); |
||
15 | |||
16 | require_once __DIR__ . '/vendor/autoload.php'; |
||
17 | |||
18 | register_shutdown_function('shutdown'); |
||
19 | |||
20 | if (extension_loaded('pcntl')) { |
||
21 | function catchSignals() { exit; } |
||
0 ignored issues
–
show
|
|||
22 | |||
23 | pcntl_signal(SIGINT, 'catchSignals'); |
||
24 | pcntl_signal(SIGTERM, 'catchSignals'); |
||
25 | } |
||
26 | |||
27 | set_exception_handler('exceptionHandler'); |
||
28 | |||
29 | use Source\Infra\Logger\Log; |
||
30 | |||
31 | if (isset($argv) && in_array('--debug', $argv)) { |
||
32 | Log::init(); |
||
33 | } |
||
34 | |||
35 | Log::info('Starting E-mail Service...'); |
||
36 | |||
37 | while (true) { |
||
38 | try { |
||
39 | Log::info('Initing listener...'); |
||
40 | |||
41 | new Source\Core\Listener(RABBITMQ_QUEUE, RABBITMQ_EXCHANGER); |
||
42 | } |
||
43 | catch (\Throwable $exception) { |
||
44 | Log::exception($exception); |
||
45 | } |
||
46 | finally { |
||
47 | sleep(5); |
||
48 | } |
||
49 | } |
||
50 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.