Cargue XML remoto desde Google App Engine para PHP

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 contenedor http, but that does not seem to work this way. I have had a look to to the GAE Obtención de URL documentation, too.

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

preguntado el 22 de septiembre de 13 a las 22:09

Puedes revisar $http_response_header después de simplexml_load_file to see if it is getting any response from server? -

Tried! $http_response_header = NULL -

1 Respuestas

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

Intenta poner

libxml_disable_entity_loader(false);

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

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"

Respondido el 24 de Septiembre de 13 a las 16:09

I am doing this, it seems that the setting is lost during "autoscaling" - as it will only work for the first few requests. - vidadeguente

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.