This repository was archived by the owner on Jun 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfork.php
More file actions
54 lines (41 loc) · 1.36 KB
/
fork.php
File metadata and controls
54 lines (41 loc) · 1.36 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
51
52
53
54
<?php
function ping_fork() {
$hosts_ip = array(
'machine1' => array('0.0.0.0', '0'),
'machine2' => array('0.0.0.0', '0')
);
$pids = array();
$db = new SQLite3('ifstat/hosts.sqlite');
$db->exec('CREATE TABLE IF NOT EXISTS hosts_status (host_name VARCHAR(10), host_status VARCHAR(5));');
$db->exec("DELETE FROM hosts_status;");
foreach($hosts_ip as $host_name => $host){
$pids[$host_name] = pcntl_fork();
if(!$pids[$host_name]) {
$socket = @fsockopen($host[0], $host[1], $errno, $errstr, 3);
if($socket && !$errno){$status = 'up';}else{$status = 'down';}
if($db->busyTimeout(5000)){
$db->exec("INSERT INTO hosts_status VALUES ('$host_name', '$status');");
}
exit();
}
}
foreach($pids as $host_name => $pid){
pcntl_waitpid($pid, $status, WUNTRACED);
}
$results = $db->query('select * from hosts_status;');
$html = '';
$html .= '<table cellspacing="10px">';
$c=0;
while($host = $results->fetchArray(SQLITE3_ASSOC)){
if($c == 0){$html .= '<tr>';}
$html .= '<td class="ping ping_'.$host['host_status'].'">'.$host['host_name'].'</td>';
$c++;
if($c == 2){$c = 0; $html .= '</tr>';}
}
if($c != 0){$html .= '</tr>';}
$html .= '</table>';
$db->exec("DELETE FROM hosts_status;");
return $html;
}
echo ping_fork();
?>