-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtermination-lock.php
45 lines (34 loc) · 993 Bytes
/
termination-lock.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
declare(strict_types=1);
use Redbitcz\Utils\Pcntl\Signals;
use Redbitcz\Utils\Process\ProcessTerminationLock;
require_once __DIR__ . '/../../vendor/autoload.php';
if (ProcessTerminationLock::isAvailable() === false) {
echo "WARNING: PHP doesn't implemented the PCNTL extensions, signal will be handled by system default handler! ";
}
/**
* Watch to SIGINT signal for test with Ctrl-C, but default termination by SIGTERM
*/
ProcessTerminationLock::setSignalTypes([Signals::SIGINT]);
function announceSignal(): void
{
echo " [Registered SIGINT signal] ";
}
function announceExit(): void
{
echo " [Exiting by holded signal]\n";
}
while (true) {
ProcessTerminationLock::lock('announceSignal');
echo "\nLocked: ";
for ($i = 0; $i < 50; $i++) {
echo ".";
usleep(100000);
}
ProcessTerminationLock::unlock('announceExit');
echo "\nUnlocked: ";
for ($i = 0; $i < 50; $i++) {
echo ".";
usleep(100000);
}
}