xpaw/php-minecraft-query
Composer 安装命令:
composer require xpaw/php-minecraft-query
包简介
PHP library to query Minecraft servers
关键字:
README 文档
README
This library can be used to query Minecraft servers for some basic information.
⚠️ Please do not create issues when you are unable to retrieve information from a server, unless you can prove that there is a bug within the library.
Differences between Ping and Query
There are two methods of retrieving information about a Minecraft server.
Ping
Ping protocol was added in Minecraft 1.7 and is used to query the server for minimal amount of information (hostname, motd, icon, and a sample of players). This is easier to use and doesn't require extra setup on server side. It uses TCP protocol on the same port as you would connect to your server.
MinecraftPing class contains a method QueryOldPre17 which can be used to query servers on version 1.6 or older.
Query
This method uses GameSpy4 protocol, and requires enabling query listener in your server.properties like this:
enable-query=true
query.port=25565
Query allows to request a full list of servers' plugins and players, however this method is more prone to breaking, so if you don't need all this information, stick to the ping method as it's more reliable.
RCON
It is possible to send console commands to a Minecraft server remotely using the Source RCON protocol. Use PHP Source Query library for your RCON needs.
SRV DNS record
This library automatically tries to resolve SRV records. If you do not wish to do so, pass false as the fourth param in the constructor (after timeout param).
Installation
composer require xpaw/php-minecraft-query
Example
require __DIR__ . '/vendor/autoload.php'; 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(); } }
If you want to get ping info from a server that uses a version older than Minecraft 1.7,
then use function QueryOldPre17 instead of Query.
If the server has query enabled (enable-query), then you can use MinecraftQuery to retrieve more information about a server.
require __DIR__ . '/vendor/autoload.php'; 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( ); }
For Bedrock servers (MCPE) use ConnectBedrock instead of Connect:
require __DIR__ . '/vendor/autoload.php'; use xPaw\MinecraftQuery; use xPaw\MinecraftQueryException; $Query = new MinecraftQuery( ); try { $Query->ConnectBedrock( 'localhost', 19132 ); print_r( $Query->GetInfo( ) ); } catch( MinecraftQueryException $e ) { echo $e->getMessage( ); }
License
xpaw/php-minecraft-query 适用场景与选型建议
xpaw/php-minecraft-query 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105.74k 次下载、GitHub Stars 达 742, 最近一次更新时间为 2014 年 12 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「minecraft」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xpaw/php-minecraft-query 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xpaw/php-minecraft-query 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xpaw/php-minecraft-query 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Allow users to use the head of a Minecraft skin as avatar.
PHP library retrieve game servers status from various types of games.
A PHP Library For the Minecraft Custom Heads Value.
Simple Rcon class for php
Minecraft Server Status Query, written in PHP, with online players, motd, favicon and more server related informations without plugins and enable-query.
A PHP Library to convert between three different Minecraft UUID Formats.
统计信息
- 总下载量: 105.74k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 745
- 点击次数: 19
- 依赖项目数: 4
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2014-12-12