首页 > 解决方案 > PHP Source Query 适用于本地主机但不适用于服务器

问题描述

我已使用此https://github.com/xPaw/PHP-Source-Query API 来查询网站上的 ARK 服务器信息。一切都在本地主机上完美运行,但在网络服务器上上传时却不行。PHP 在服务器上以其他方式工作,但不仅仅是这一功能。服务器上的 Apache 错误日志在页面加载时这样说:

“PHP 解析错误:语法错误,意外的 ''xPaw/SourceQuery /SourceQuery'' (T_CONSTANT_ENCAPSED_STRING),在 /var/www/jamon 中需要标识符 (T_STRING) 或函数 (T_FUNCTION) 或 const (T_CONST) 或 \\ (T_NS_SEPARATOR) /serverinfo.php 第 4 行,引用者: https ://jamonparadigm.com/servers "

Web 服务器正在运行 PHP 7。 serverinfo.php 如下所示:

<?php
require __DIR__ . '/SourceQuery/bootstrap.php';

use xPaw\SourceQuery\SourceQuery;

// For the sake of this example
Header( 'Content-Type: text/plain' );
Header( 'X-Content-Type-Options: nosniff' );

// The Island
define( 'SQ_SERVER_ADDR', '159.69.56.156' );
define( 'SQ_SERVER_PORT', 27000 );
define( 'SQ_TIMEOUT',     1 );
define( 'SQ_ENGINE',      SourceQuery::SOURCE );

$Query = new SourceQuery( );

try
{
    $Query->Connect( SQ_SERVER_ADDR, SQ_SERVER_PORT, SQ_TIMEOUT, SQ_ENGINE );

    $islandInfo =  $Query->GetInfo( );
    $islandPlayers = $islandInfo['Players'] . "/" . $islandInfo['MaxPlayers'];
    $islandVersion = trim(substr($islandInfo['HostName'], strpos($islandInfo['HostName'], '(')), "()");
    $islandStatus = '<span class="text-success">online</span>';
    $islandInfo2 = $Query->GetRules();
    $islandDay = $islandInfo2['DayTime_s'];
}
catch( Exception $e )
{
    $islandPlayers = "0/0";
    $islandVersion = "";
    $islandStatus = '<span class="text-danger">offline</span>';
    $islandDay = "";
}
finally
{
    $Query->Disconnect( );
}
?>

可以做些什么来解决这个问题?

标签: phpsteam

解决方案


推荐阅读