By Patrick K. (Nox Nebula).
http://www.silexboard.org/, https://github.com/NoxNebula/Minecraft-Server-Status
This is a lightweight script, which reads the server infos of Minecraft servers.
The simple script (MinecraftServerStatusSimple.class.php) supports Minecraft server beta 1.8 or higher.
The newer one (MinecraftServerStatus.class.php) uses the query method and supports Minecraft servers beginning with Minecraft 1.0.0.
- Query the server if "enable-query" is activated and parse the server infos.
The simple one read and parse the build-in server infos from minecraft beta 1.8 or higher servers. - OOPHP
- Handles some errors
- Easy to use
- Lightweight
- Fallback
- PHP 5.4.0 (You need to edit the scripts, if you want to use older php versions)
- PHP allowed stream sockets (stream_socket_client, fwrite, fread, fclose)
Make sure in your server.properties are the following lines:
enable-query=true
query.port=25565
<?php
require_once('MinecraftServerStatus.class.php');
$Server = new MinecraftServerStatus('example-minecraft-host.com');
?>
MinecraftServerStatus($Host, $Port = 25565, $Timeout = 1)
You can easily check if the server is online or offline:
$Server->Get('online');
This will return a boolean, if it's true, the server is online else false.
echo $Server->Get('numplayers').' / '.$Server->Get('maxplayers');
foreach($Server->Get('players') as $Player)
echo $Player.'<br>';
$ServerStatus = $Server->Get();
The most of these hooks are only available if the server has query enabled or the server is not vanilla.
'hostname'
'gametype'
'game_id'
'version'
'plugins'
'map'
'numplayers'
'maxplayers'
'hostport'
'hostip'
'online'
'software'
note to check if$Server->Get('hook');
return the expected value (No hook = false).
You can just use the "MinecraftServerStatus.class.php" file without the simple one, but if you want a fallback (fewer server infos but works everytime if the requested server is ok) you also should have the "MinecraftServerStatusSimple.class.php" in the same folder.