-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathreinit_1.phpt
74 lines (69 loc) · 1.64 KB
/
reinit_1.phpt
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
--TEST--
swoole_timer: reinit [1]
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Timer;
const RES_FILE = __DIR__ . '/result.txt';
file_put_contents(RES_FILE, "");
$pm = new ProcessManager;
$pm->setWaitTimeout(-1);
$pm->parentFunc = function ($pid) use ($pm) {
$fp = fopen(RES_FILE, "rw");
while (!feof($fp)) {
$line = fgets($fp);
if ($line) {
echo $line;
}
}
if (IS_MAC_OS) {
$pm->kill();
}
};
$pm->childFunc = function () use ($pm) {
$server = new Swoole\Server("0.0.0.0", $pm->getFreePort(), SWOOLE_PROCESS);
$server->set([
'worker_num' => 1,
'log_file' => '/dev/null',
]);
$server->on('start', function (Swoole\Server $server) use ($pm) {
file_put_contents(RES_FILE, "start\n", FILE_APPEND);
static $i = 0;
$id = Timer::tick(100, function ($timerId) use (&$i, $server, $pm) {
file_put_contents(RES_FILE, "timer 1\n", FILE_APPEND);
if (($i++) == 4) {
Timer::clear($timerId);
$server->shutdown();
$pm->wakeup();
}
});
});
static $j = 0;
Timer::tick(50, function ($timerId) use (&$j) {
file_put_contents(RES_FILE, "timer 2\n", FILE_APPEND);
if (($j++) == 5) {
Timer::clear($timerId);
}
});
$server->on('receive', function () { });
$server->start();
};
$pm->childFirst();
$pm->run();
unlink(RES_FILE);
?>
--EXPECT--
start
timer 2
timer 2
timer 1
timer 2
timer 2
timer 1
timer 2
timer 2
timer 1
timer 1
timer 1