问题
I've just started getting an intermittent error on all pages of a joomla dev site I'm running on localhost.
The full warning is:
Warning: simplexml_load_file(): I/O warning : failed to load external entity "/site/language/en-GB/en-GB.xml" in /site/libraries/joomla/language/language.php on line 1354
The strange thing is that it is intermittent and a few refreshes will usually resolve the problem.
Is there a code problem that could be causing this or is it something else?
回答1:
Let me put it here just in case for somebody will google for an answer and the solution with not thread-safe libxml_disable_entity_loader(false)
will not be applicable. The potential vulnerability of enabling the entity loader system-wide is shown below:
<!DOCTYPE scan [<!ENTITY test SYSTEM
"php://filter/read=convert.base64-encode/resource=/etc/passwd">]>
<scan>&test;</scan>
The problem caused by the lack of thread safety is explained here. Although one might either register her own entity loader with libxml_set_external_entity_loader
, or use locks to protect calls to libxml_disable_entity_loader
, these solutions seem a bit puzzling.
The good news is that the problem with external entities affects only the functions dealing with files (e.g. simplexml_load_file, DOMDocument::schemaValidate and like). That makes the solution straight and simple. First load file content as string and then execute the respective libxml string-oriented function.
simplexml_load_string(file_get_contents($xml));
and/or
$xml = new DOMDocument('1.0', 'UTF8');
$xml->loadXML(file_get_contents($xmlFile));
$xml->schemaValidateSource(file_get_contents($xsdFile));
Hope it helps somebody.
回答2:
It's early days yet to say conclusively that this fix works but it seems to have fixed it for now.
EDIT: Haven't seen any reoccurrence since making this change so I can confirm that this has resolved the problem.
add libxml_disable_entity_loader(false);
to joomla's index.php
Credit goes to Corneliu on the Joomla forum for his post in this thread:
J! 3.1.6/3.2 simplexml_load_file, JForm::getInstance errors
来源:https://stackoverflow.com/questions/20534866/intermittent-simplexml-load-file-i-o-warning-on-local-joomla-site