Magento – Warning: simplexml_load_file(): I/O Magento warning : failed to load external entity “/var/www/app/etc/local.xml”

magento-1.8xml

I have this issue in my magento installation

Warning: simplexml_load_file(): I/O warning : failed to load external entity "/var/www/app/etc/local.xml" in /var/www/app/Mage.php on line 767

setting libxml_disable_entity_loader(false); solves this issue but I will have to do it for every simplexml_load_file()

Is there any better solution and also if anyone could shed some light on how this issue might have occurred?

Best Answer

As a followup on this: I have the same issue as well - randomly - when loading any XML file using simplexml_load_file() on the same server with any application (WordPress, Magento, Joomla). The reason is definitely not that the XML file contains bad characters, bad formatting or does not exist. The issue seems to be related to a pending PHP bug, that occurs when too many PHP applications rely on SimpleXML on the same server.

On a deeper level, the SimpleXML library uses kind of caching that is persistent across multiple requests within the same PHP thread (PHP-FPM instance, mod_php instance, etcetera). It is said to be fixed by updating PHP 5.4, but that hasn't worked yet for me. It does not occur with PHP 5.5 or higher.

One fix is to override app/Mage.php with the following - locate the commented line and replace it with 3 lines. Core hack, ugly, should not be done, wash your mouth. But it works.

//$localConfig = simplexml_load_file($localConfigFile); $xmlString = file_get_contents($localConfigFile); $localConfig = simplexml_load_string($xmlString);

Another workaround is listed here: https://bugs.php.net/bug.php?id=64938