Skip to content

Examples v3

Austin Bischoff edited this page Mar 2, 2015 · 13 revisions

GameQ Examples

Here is a simple example to get you off the ground

// Define the servers you wish you query
$servers = [
    [
    'type'    => 'css',
    'host'    => '127.0.0.1:27015',
    ]
];

$GameQ = new \GameQ\GameQ(); // or $GameQ = \GameQ\GameQ::factory();
$GameQ->addServers($servers);
$GameQ->setOption('timeout', 5); // seconds

$results = $GameQ->process();
print_r($results);

Loading servers from a file or set of files

If your list of servers does not change often you can use a JSON based file to define your servers and have them loaded in to GameQ. This only supports JSON currently. Any file paths passed that are invalid, unreadable or are improperly formatted are automatically ignored.

$GameQ = new \GameQ\GameQ(); // or $GameQ = \GameQ\GameQ::factory();
$GameQ->addServersFromFiles('/path/to/your/servers.json');
'''

You can also pass an array of files to load if you have multiple lists you maintain.

// List of JSON files
$files = [
    '/path/to/your/server_list1.json',
    '/path/to/your/server_list2.json',
    ...
];

$GameQ = new \GameQ\GameQ(); // or $GameQ = \GameQ\GameQ::factory();
$GameQ->addServersFromFiles($files);
...

Teamspeak 2 & 3

For Teamspeak versions 2 and 3 the query_port server option is required due to how Teamspeak operates. Note the ports used are the defaults and your server may have different ports.

$GameQ = new \GameQ\GameQ();
$GameQ->addServer([
    'type'    => 'teamspeak3',
    'host'    => '127.0.0.1:9987',
    'options' => [
        'query_port' => 10011,
    ],
]);

$results = $GameQ->process();