PHP code example of xpaw / php-minecraft-query

1. Go to this page and download the library: Download xpaw/php-minecraft-query library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

xpaw / php-minecraft-query example snippets




use xPaw\MinecraftPing;
use xPaw\MinecraftPingException;

$Query = null;

try
{
	$Query = new MinecraftPing( 'localhost', 25565 );

	print_r( $Query->Query() );
}
catch( MinecraftPingException $e )
{
	echo $e->getMessage();
}
finally
{
	if( $Query !== null )
	{
		$Query->Close();
	}
}



use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;

$Query = new MinecraftQuery( );

try
{
	$Query->Connect( 'localhost', 25565 );

	print_r( $Query->GetInfo( ) );
	print_r( $Query->GetPlayers( ) );
}
catch( MinecraftQueryException $e )
{
	echo $e->getMessage( );
}



use xPaw\MinecraftQuery;
use xPaw\MinecraftQueryException;

$Query = new MinecraftQuery( );

try
{
	$Query->ConnectBedrock( 'localhost', 19132 );

	print_r( $Query->GetInfo( ) );
}
catch( MinecraftQueryException $e )
{
	echo $e->getMessage( );
}

composer