Reputation: 7763
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?
Upvotes: 3
Views: 1313
Reputation: 7054
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"
Upvotes: 11