Server online check
Op een server draai ik a.t.m. TeamSpeak, nu wil ik via php checken of de server aanstaat. Dit heb ik al geprobeerd via een port check met fsockopen(). Alleen werkt dat niet, wel op de port van apache. Hoe kan ik dit verhelpen of is er een andere mogelijkheid?
Zoiets is het wel, alleen deze werkt niet. Zelfs met fsockopen() werkt hij nog beter.
Code (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
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
75
76
77
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
75
76
77
<?
function pre($var1){
echo "<pre>";
print_r($var1);
echo "</pre>";
}
class Teamspeak {
var $socket;
var $address;
var $queryPort;
var $udpPort;
function Teamspeak() {
$this->address = 'blabla.blabla.compom'; // can be ip address or url
$this->queryPort = 51234; // default 51234, must be accessible and usable. check server.ini
$this->udpPort = 8767; // default 8767
}
function getSocket($errno, $errstr, $timeout) {
global $errno, $errstr;
@$this->socket = fsockopen($this->address, $this->queryPort, $errno, $errstr, $timeout);
if($this->socket and fread($this->socket, 4) == "[TS]") {
fgets($this->socket, 128);
$this->sendQuery("sel ".$this->udpPort);
if($this->getOK()) {
return true;
} else {
return false;
}
}
return false;
}
function sendQuery($query) {
fputs($this->socket, $query."\n");
}
function getOK() {
$result = fread($this->socket, 2);
fgets($this->socket, 128);
return($result == "OK");
}
function getPlayer() {
$this->sendQuery("pl");
$playerList = array();
$i = 0;
do {
$playerinfo = fscanf($this->socket, "%s %d %d %d %d %d %d %d %d %d %d %d %d %s %s");
list($playerid, $channelid, $receivedpackets, $receivedbytes, $sentpackets, $sentbytes, $d, $d, $totaltime, $idletime, $d, $d, $d, $s, $playername) = $playerinfo;
echo $playerinfo;
if($playerid != "OK" && $playername != "") {
$playerList[$i]['id'] = $playerid;
$playerList[$i]['name']= $playername;
$i++;
}
} while($playerid != "OK");
return $playerList;
}
function closeSocket() {
fputs($this->socket, "quit");
fclose($this->socket);
}
}
$players = array(); //maak array waar spelers in moeten komen
$xxx = new Teamspeak(); //maak nieuwe instantie van het teamspeak object
pre($xxx);
$xxx->getSocket($x1,$x2,$x3);
pre($xxx);
$players = $xxx->getPlayer(); //Pak alle players en geef die terug aan de array
pre($players);
?>
function pre($var1){
echo "<pre>";
print_r($var1);
echo "</pre>";
}
class Teamspeak {
var $socket;
var $address;
var $queryPort;
var $udpPort;
function Teamspeak() {
$this->address = 'blabla.blabla.compom'; // can be ip address or url
$this->queryPort = 51234; // default 51234, must be accessible and usable. check server.ini
$this->udpPort = 8767; // default 8767
}
function getSocket($errno, $errstr, $timeout) {
global $errno, $errstr;
@$this->socket = fsockopen($this->address, $this->queryPort, $errno, $errstr, $timeout);
if($this->socket and fread($this->socket, 4) == "[TS]") {
fgets($this->socket, 128);
$this->sendQuery("sel ".$this->udpPort);
if($this->getOK()) {
return true;
} else {
return false;
}
}
return false;
}
function sendQuery($query) {
fputs($this->socket, $query."\n");
}
function getOK() {
$result = fread($this->socket, 2);
fgets($this->socket, 128);
return($result == "OK");
}
function getPlayer() {
$this->sendQuery("pl");
$playerList = array();
$i = 0;
do {
$playerinfo = fscanf($this->socket, "%s %d %d %d %d %d %d %d %d %d %d %d %d %s %s");
list($playerid, $channelid, $receivedpackets, $receivedbytes, $sentpackets, $sentbytes, $d, $d, $totaltime, $idletime, $d, $d, $d, $s, $playername) = $playerinfo;
echo $playerinfo;
if($playerid != "OK" && $playername != "") {
$playerList[$i]['id'] = $playerid;
$playerList[$i]['name']= $playername;
$i++;
}
} while($playerid != "OK");
return $playerList;
}
function closeSocket() {
fputs($this->socket, "quit");
fclose($this->socket);
}
}
$players = array(); //maak array waar spelers in moeten komen
$xxx = new Teamspeak(); //maak nieuwe instantie van het teamspeak object
pre($xxx);
$xxx->getSocket($x1,$x2,$x3);
pre($xxx);
$players = $xxx->getPlayer(); //Pak alle players en geef die terug aan de array
pre($players);
?>
Die gebruik ik, zeer goed programma. Maar is meer bedoelt voor bedrijven die meerdere server hebben draaien. Werk o.a onder:
Windows
Linux
Vmware
Enz
http://www.tsviewer.com/
Dit gebruiken wij :)
Dit gebruiken wij :)