-
Notifications
You must be signed in to change notification settings - Fork 16
/
start.php
48 lines (41 loc) · 1000 Bytes
/
start.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
46
47
48
<?php
$servers = [
['name' => 'Sun'],
['name' => 'Mercury'],
['name' => 'Venus'],
['name' => 'Earth'],
['name' => 'Mars'],
['name' => 'Jupiter'],
['name' => 'Saturn'],
['name' => 'Uranus'],
['name' => 'Neptune'],
['name' => 'Pluto']
];
foreach ($servers as $server) {
forkOff('system', ['php slave.php ' . $server['name']]);
echo $server['name'] . ' started!' . PHP_EOL;
sleep(5);
}
function forkOff($lambda, $args)
{
$pid = pcntl_fork();
if ($pid === -1) {
die('Forking failed.');
}
if ($pid === 0) {
while (true) {
$pid = pcntl_fork();
if ($pid === -1) {
die('Forking failed.');
}
if ($pid === 0) {
exit(call_user_func_array($lambda, $args));
}
$ret = pcntl_waitpid($pid, $status);
if ($ret !== $pid) {
exit('Should not happen.');
}
}
}
return;
}