MinecraftStatus library allows you to communicate with minecraft servers using the most popular protocols.
This library can be installed by issuing the following command:
composer require dev-lancer/minecraft-statusMinecraftJavaStatus uses the TCP protocol to communicate with the Minecraft server in the java edition and bedrock edition, it uses the port on which the server is running. Ping provides the most necessary information (hostname, motd, favicon, and a sample of players). Thanks to its simplicity, it does not require any configuration on the server side, communication works with servers from version 1.7 and above.
To communicate with a server which has a version lower than 1.7, use the MinecraftJavaPreOld17Status class
For bedrock edition servers use class MinecraftBedrockStatus
MinecraftJavaQuery uses GameSpy 4 protocol for communication, so you should start listening in the server properties. Query allows you to request more information about the server, but has more security vulnerabilities.
Example: MinecraftJavaQuery
This method uses GameSpy4 protocol, and requires enabling query listener in your server.properties like this:
enable-query=true
query.port=25565
<?php
use \DevLancer\MinecraftStatus\MinecraftJavaQuery;
require_once ("vendor/autoload.php");
$host = ""; //Address server minecraft
$port = 25565; //from query.port
$timeout = 3;
$resolveSVR = true;
$query = new MinecraftJavaQuery($host, $port, $timeout, $resolveSVR);
$query->connect();
print_r($query->getInfo());Example: MinecraftBedrockStatus
Use this class for bedrock edition servers
In QueryBedrock you do not need to set anything in the properties of the server, the port on which the server runs is used to communicate with the server
<?php
use \DevLancer\MinecraftStatus\MinecraftBedrockStatus;
require_once ("vendor/autoload.php");
$host = ""; //Address server minecraft
$port = 19132;
$timeout = 3;
$resolveSVR = true;
$query = new MinecraftBedrockStatus($host, $port, $timeout, $resolveSVR);
$query->connect();
print_r($query->getInfo());Example: MinecraftJavaStatus
<?php
use \DevLancer\MinecraftStatus\MinecraftJavaStatus;
use \DevLancer\MinecraftStatus\MinecraftJavaPreOld17Status;
require_once ("vendor/autoload.php");
$host = ""; //Address server minecraft
$port = 25565;
$timeout = 3;
$resolveSVR = true;
$ping = new MinecraftJavaStatus($host, $port, $timeout, $resolveSVR);
//$ping = new MinecraftJavaPreOld17Status($host, $port, $timeout, $resolveSVR); //use when version is older than Minecraft 1.7
$ping->connect();
print_r($ping->getInfo());If you want to get ping info from a server that uses a version older than Minecraft 1.7, then use class PingPreOld17 instead of Ping.
| MinecraftJavaQuery | MinecraftBedrockStatus | MinecraftJavaStatus | MinecraftJavaPreOld17Status | |
|---|---|---|---|---|
| connect() | X | X | X | X | 
| isConnected() | X | X | X | X | 
| disconnect() | X | X | X | X | 
| getPlayers() | X | X | ||
| getCountPlayers() | X | X | X | X | 
| getMaxPlayers() | X | X | X | X | 
| getInfo() | X | X | X | X | 
| getFavicon() | X | |||
| getDelay() | X | |||
| setTimeout() | X | X | X | X | 
| getTimeout() | X | X | X | X | 
| setEncoding() | X | X | X | X | 
| getEncoding() | X | X | X | X | 
| isResolveSRV() | X | X | X | X | 
| getHost() | X | X | X | X | 
| getPort() | X | X | X | X | 
| getMotd() | X | X | X | X | 
| getProtocol() | X | X | X | 
Sets the timeout for the connection
setTimeout(int $timeout): voidSets the character encoding for the returned values using the getInfo() and getPlayers() methods
setEncoding(string $encoding): voidConnects to the server.
There may be a ConnectionException which means that the connection to the server has failed
or a ReceiveStatusException when the connection to the server has succeeded,
but the communication has not been successful.
When the method is used again, it disconnects from the server and establishes a new connection
connect(): selfDisconnects the connection to the server
disconnect(): voidUsing the following methods when not connected to the server will throw a NotConnectedException exception,
in case you have successfully connected to the server but the communication does not work then they will return a default value of empty
It returns a full array with the information it was able to obtain.
getInfo(): arrayReturns arrays of users
getPlayers(): arrayReturns the number of online players
getCountPlayers(): intReturns the number of server slots
getMaxPlayers(): intReturns the favicon as a string
getFavicon(): stringReturns the connection delay [ms]
getDelay(): intReturns a motd of the server
getMotd(): stringReturns the server protocol number
getProtocol(): intReturns the server host
getHost(): stringReturns a port
getPort(): intReturns the character encoding used to encode the values in the getInfo() and getPlayers() methods.
getEncoding(): stringReturns a timeout.
getTimeout(): intReturns true when a successful connection to the server is made regardless of whether a ReceiveStatusException exception is thrown.
isConnected(): boolReturns true when an attempt to resolve the SRV occurs on a connection, regardless of the result.
isResolveSRV(): boolThe library allows automatic resolution of SRV records, by default the service is enabled, to disable it you must specify false in the fourth parameter of the constructor