Load remote XML from Google App Engine for PHP

…衆ロ難τιáo~ 提交于 2020-01-04 04:34:10

问题


I want to load a remote and dynamic XML file from a third party server into my GAE-PHP application:

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

I have tried to load the XML information using the simplexml_load_file function:

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

But that leads always to this error:

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

So, I have changed the code and I try load the XML as a generic text file. This way, it works as expected:

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

I was thinking the two functions get the remote contents using the same http wrapper, but that does not seem to work this way. I have had a look to to the GAE URL Fetch documentation, too.

My question is: Why the first approach does not work? Am I missing something?


回答1:


We've disabled automatic loading of external entities by default, you have to opt in.

Try putting

libxml_disable_entity_loader(false);

before you're call. This is documented in the Disabled Functions section

This involves one additional step: First, you must create a php.ini file containing this line:

google_app_engine.enable_functions = "libxml_disable_entity_loader"


来源:https://stackoverflow.com/questions/18949081/load-remote-xml-from-google-app-engine-for-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!