示例#1
0
function checkServer($config)
{
    // Check array
    if (!is_array($config) || !isset($config['host']) || !isset($config['port']) || !isset($config['warn'])) {
        print 'Invalid arguments.' . EOL;
        printSummary();
        return 3;
    }
    $query = new MinePHPQuery($config['host'], $config['port']);
    // Server down
    if (!$query->isOnline()) {
        print 'CRITICAL: Server ' . $config['host'] . ':' . $config['port'] . ' unreachable.' . EOL;
        return 2;
    }
    // Check players
    if ($query->getPlayerCount() / $query->getMaxPlayers() * 100 >= $config['warn']) {
        print 'WARNING: Player number threshold ' . $config['warn'] . '% reached: ' . $query->getPlayerCount() . '/' . $query->getMaxPlayers() . EOL;
        return 1;
    }
    // Everything ok
    print 'MINECRAFT OK: ' . $query->getPlayerCount() . '/' . $query->getMaxPlayers() . ' players. ' . $query->getSoftware() . ' - Version ' . $query->getVersion() . EOL;
    return 0;
}
示例#2
0
<?php

/**
 * @author    Janek Ostendorf (ozzy) <*****@*****.**>
 * @copyright Copyright (c) 2013 Janek Ostendorf
 * @license   http://opensource.org/licenses/gpl-3.0.html GNU General Public License, version 3
 */
// Loading should be done by composer
require_once __DIR__ . '/vendor/autoload.php';
// If not using composer, use this instead:
// require_once __DIR__.'/src/MinePHPQuery.class.php';
$query = new MinePHPQuery('localhost', 25565);
if ($query->isOnline()) {
    echo 'Server is online. ' . $query->getPlayerCount() . ' players are playing currently';
} else {
    echo 'Server is offline :sadface: :(';
}