【问题标题】:Load remote XML from Google App Engine for PHP从 Google App Engine for PHP 加载远程 XML
【发布时间】:2013-09-22 21:45:06
【问题描述】:

我想将来自第三方服务器的远程动态 XML 文件加载到我的 GAE-PHP 应用程序中:

$itemId = 5;
$uri = "http://www.myserver.com/getInfoItem.php?itemId={$itemId}&format=xml";

我尝试使用 simplexml_load_file 函数加载 XML 信息:

if ($xmlItem = simplexml_load_file($uri)) {
  // Code dealing with the XML info
}

但这总是会导致这个错误:

PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "..."

所以,我更改了代码并尝试将 XML 作为通用文本文件加载。这样,它可以按预期工作:

if ($fileContents = file_get_contents($uri)) {
  $xmlItem = simplexml_load_string($fileContents);
  // Code dealing with the XML info
}

我在想这两个函数使用相同的http wrapper 来获取远程内容,但这种方式似乎不起作用。我也看过 GAE URL Fetch 文档。

我的问题是:为什么第一种方法不起作用?我错过了什么吗?

【问题讨论】:

  • 您能否在simplexml_load_file 之后检查$http_response_header 以查看它是否收到来自服务器的任何响应?
  • 试过了! $http_response_header = NULL

标签: php google-app-engine


【解决方案1】:

默认情况下,我们已禁用自动加载外部实体,您必须选择加入。

试试看

libxml_disable_entity_loader(false);

在你打电话之前。这记录在Disabled Functions 部分

这涉及一个额外的步骤:首先,您必须创建一个包含此行的php.ini 文件:

google_app_engine.enable_functions = "libxml_disable_entity_loader"

【讨论】:

  • 我正在这样做,似乎设置在“自动缩放”期间丢失了 - 因为它仅适用于前几个请求。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-16
  • 2011-07-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多