forked from MCNewsTools/PHP-Minecraft-Query-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApiPing.php
37 lines (28 loc) · 785 Bytes
/
ApiPing.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
<?php
/*
PHP Minecraft Query API
https://github.com/MCServerStatus/PHP-Minecraft-Query-API
*/
use xPaw\MinecraftPing;
use xPaw\MinecraftPingException;
require_once __DIR__ . '/src/MinecraftPing.php';
require_once __DIR__ . '/src/MinecraftPingException.php';
$Timer = MicroTime(true);
$InfoPing = false;
$QueryPing = null;
try {
$QueryPing = new MinecraftPing(MQ_SERVER_ADDR, MQ_SERVER_PORT, MQ_TIMEOUT);
$InfoPing = $QueryPing->Query();
if($InfoPing === false) {
$QueryPing->Close();
$QueryPing->Connect();
$InfoPing = $QueryPing->QueryOldPre17();
}
} catch(MinecraftPingException $e) {
$Exception = $e;
}
if($QueryPing !== null) {
$QueryPing->Close();
}
$Timer = Number_Format(MicroTime(true) - $Timer, 4, '.', '');
?>