-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathonReload.phpt
58 lines (54 loc) · 1.53 KB
/
onReload.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
--TEST--
swoole_server: server beforeRelaod and afterReload event
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
--FILE--
<?php
error_reporting(0);
require __DIR__ . '/../include/bootstrap.php';
use Swoole\Server;
use Swoole\Atomic;
$WorkerStartAtomic = new Atomic(0);
$pm = new SwooleTest\ProcessManager;
$pm->parentFunc = function ($pid) use ($pm,$argv) {
sleep(2);
$script_name = $argv[0];
$ret = shell_exec("ps aux | grep $script_name | grep -v 'grep'");
Assert::assert($ret != "");
$pm->kill();
echo "DONE\n";
};
$pm->childFunc = function () use ($pm, $WorkerStartAtomic) {
$serv = new Server('127.0.0.1', $pm->getFreePort(), SWOOLE_PROCESS);
$serv->set([
'log_file' => TEST_LOG_FILE,
"worker_num" => 2,
"task_worker_num" => 2,
"max_wait_time" => 1,
]);
$serv->on("BeforeReload", function (Server $serv) {
var_dump("BeforeReload");
});
$serv->on("AfterReload", function (Server $serv) {
var_dump("AfterReload");
});
$serv->on("WorkerStart", function (Server $serv, $worker_id) use ($pm, $WorkerStartAtomic) {
$WorkerStartAtomic->add(1);
if ($WorkerStartAtomic->get() === 4) {
$serv->reload();
$pm->wakeup();
}
});
$serv->on('Receive', function ($serv, $fd, $tid, $data) {
});
$serv->on('Task', function ($serv,$task_id, $reactor_id, $params) {
});
$serv->start();
};
$pm->childFirst();
$pm->run();
?>
--EXPECT--
string(12) "BeforeReload"
string(11) "AfterReload"
DONE