-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.php
More file actions
50 lines (39 loc) · 1.1 KB
/
server.php
File metadata and controls
50 lines (39 loc) · 1.1 KB
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
<?php
include 'init.php';
$server_manager = new ServerManager();
if (FORK_COUNT > 0) {
$isParent = true;
$children = array();
for ($x = 0; $x < FORK_COUNT; $x++) {
$pid = pcntl_fork();
if ($pid == -1) {
// TODO: Display some sort of error and exit
} else if ($pid) {
$children[] = $pid;
} else {
$isParent = false;
break;
}
}
if ($isParent) {
while ($children) {
$childPid = pcntl_wait($status);
$index = array_search($childPid, $children);
array_splice($children, $index, 1);
}
exit();
}
}
foreach ($server_config as $port => $config) {
$keys = array_keys($config);
$wrapper = array_shift($keys);
$ssl = !empty($config['ssl']) ? $config['ssl'] : null;
if ($ssl === null) {
$ssl = array();
}
if ($wrapper !== null) {
$wrapper_config = !empty($config[$wrapper]) ? $config[$wrapper] : array();
$server_manager->startServer($port, $wrapper, $wrapper_config, $ssl);
}
}
$server_manager->run();