Hi, first post here. It's the first time I've been so stuck really.
I'm using the library below to pull server data (players, time online etc) from a Steam game through the source API, however it will not work with more than one script or server at once. For example, if I copy the script into a new file and change the connection info, and include both in my HTML, only one will work. Any ideas on how to do it, or an example would be amazing.
http://github.com/xPaw/PHP-Source-Query
<?php
namespace web2;
require __DIR__ . '/SourceQuery/bootstrap.php';
use xpaw\SourceQuery\SourceQuery;
// For the sake of this example
Header( 'Content-Type: text/html' );
Header( 'X-Content-Type-Options: nosniff' );
// Edit this ->
define( 'SQ_SERVER_ADDR', 'iphere' );
define( 'SQ_SERVER_PORT', 27015 );
define( 'SQ_TIMEOUT', 3 );
define( 'SQ_ENGINE', SourceQuery::SOURCE );
// Edit this <-
$Query = new SourceQuery( );
try
{
$Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );
$info = $Query->GetInfo();
/*echo "<h1>Players: ".$info['Players' 'MaxPlayers']."</h1>";
echo "<h1>Max Players: ".$info['MaxPlayers']."<h1>"; */
var_dump($info);
echo "<p>Hostname: ".$info['HostName']."</p>";
$players = $info['Players']; $maxplayers = $info['MaxPlayers']; echo "<p>Players: ".$players . " / " . $maxplayers."</p>";
echo "<p>Map: ".$info['Map']."</p>";
echo "<p>Port: ".$info['GamePort']."</p>";
echo "<p>Version: ".$info['Version']."</p>";
}
catch( Exception $e )
{
echo $e->getMessage( );
}
finally
{
$Query->Disconnect( );
}
?>
That's for one connection. It will not work with more, although you can do it, I've seen it done. Thank you in advance!