simplexml_load_file(): I/O warning : failed to load external entity "/user-bundle/Resources/config/doctrine/model/User.orm.xml

simplexml_load_file(): i/o warning : failed to load external entity project php 74
warning: failed to load external entity xmllint
warning: simplexml_load_file
unable to load the requested class simplexml
php simplexml load file error handling
simplexml_load_file not working
php simplexml load url
simplexml_load_string not working on server

I have some issue with my production deployment of Symfony2,

I've tried many solutions, but none have worked.

I randomly have this error when accessing my symfony application on production environment:

( ! )   Fatal error: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: simplexml_load_file(): I/O warning : failed to load external entity    "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml"'    in /home/user/symfony/app/bootstrap.php.cache on line 2998
( ! )   Symfony\Component\Debug\Exception\ContextErrorException: Warning: simplexml_load_file():    I/O warning : failed to load external entity    "/home/user/symfony/vendor/friendsofsymfony/user-bundle/Resources/config/doctrine/model/User.orm.xml" in /home/user/symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php on line 736
Call Stack
#   Time    Memory  Function    Location
1   0.0000  262880  {main}( )   ../app_dev.php:0
2   0.0015  572736  Symfony\Component\HttpKernel\Kernel->handle( )  ../app_dev.php:79
3   0.1342  4023952 Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle( )    ../bootstrap.php.cache:2376
( ! )   LogicException: Request stack is empty  in /home/user/symfony/app/bootstrap.php.cache on line 2998
Call Stack
#   Time    Memory  Function    Location
1   0.3330  7110120 Symfony\Component\Debug\ErrorHandler->handleException( )    ../classes.php:0
2   0.3331  7119696 Symfony\Component\Debug\ErrorHandler->handleException( )    ../classes.php:1939

I've tried to upgrade my php version (I was in php 5.4.x and now in 5.6.4),

I've tried to upgrade lixml2 version (i am in 2.8.0 now, but i already tried to upgrade in 2.9.3)

I've constated that the version of libxml used in php is always 2.8.0, but, I haven't found the way to change this ,

I've tried to set the all directory of symfony in chmod 777

My server is a debian 7.5 server.

Maybe someone who knows this error can help me

Here is some links to differents question related to this one:

Random Error, FOSUserBundle Error and Service error

I didn't post in them because they're all outdated

[EDIT]

I found a quick fix, but it's in vendors, so it will be overrided in the first update of the doctrine update:

QuickFix in XmlDriver.php Line 737

$xmlElement = @simplexml_load_file($file);
if(!$xmlElement){
        $xmlData = file_get_contents($file);
        $xmlElement = simplexml_load_string($xmlData);
}

We got this error after we started using libxml_disable_entity_loader(true); in our code. That code is vital in preventing XXE -attacks(more info of that in here). If you don't have that in your code, it could be that you have installed/updated a bundle which has that line of code in use. Note that libxml_disable_entity_loader() is not thread safe, so if there is one piece of code on one thread that executes that line, everything on that server now has that enabled throughout the process.

The FOS-bundle seems to use xml-definitions, that in return have external entities in them. Nothing major though, but that code prevents the FOS-bundles methods from using those files correctly.

Luckily, our service got that error only in one place, and the fix was obvious: Add a libxml_disable_entity_loader(false); before executing that piece of code where the error comes from, and add libxml_disable_entity_loader(true); right after that piece of code. This way the user bundle could load the xml:s it needed, but security is not compromised.

Example:

libxml_disable_entity_loader(false);
$user = $query->getOneOrNullResult(); // This generates an error if entity loader is disabled
libxml_disable_entity_loader(true);

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O , Try to pass full directory path if you are trying to load xmls held at your server simplexml_load_file($_SERVER['DOCUMENT_ROOT']. [function.simplexml-load-file]: I/O warning : failed to load external entity (cakephp) Hot Network Questions Why doesn’t the sun fill the sky on Mercury

The error mentioned usually happens when the xml file does not exists.

You can try check if the file really exists after try to load:

if (file_exists($file)) {
    $xmlElement = @simplexml_load_file($file);
}

I tried to simulate the error locally running php interactively, the results are in down:

php > simplexml_load_file('test.xml');
PHP Warning:  simplexml_load_file(): I/O warning : failed to load external entity "test.xml" in php shell code on line 1
php > 

Note, the error above is the same that you mentioned on the question. So, the first try is use the file_exists() function to check if the file really exists after try to load it. The next step is check if the current path - using getcwd() - and the path of the file are pointing correctly to the file.

I created a file called test.xml on /tmp folder:

 <test>
        <worked>
        </worked>
    </test>

Called the interactive mode on php:

$ php -a
Interactive mode enabled

So, checked my local directory:

php > echo getcwd();
/tmp

And, tried to load the file:

php > $data = simplexml_load_file('test.xml');
php > var_dump($data);
object(SimpleXMLElement)#1 (1) {
  ["worked"]=>
  object(SimpleXMLElement)#2 (1) {
    [0]=>
    string(2) "
    "
  }
}

Note: that worked correctly. So, probably, your file does not exists or the path are incorrect. The path considers the current path /tmp plus, the file indicated on the function call test.txt, or equals to call the /tmp/test.txt file.

DDC-3020: simplexml_load_file(): I/O warning: failed to load , by user rmatrono: PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity "/path-to/doctrine/entities/mappings/my_entity.dcm.xml" in  Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.

There are some solutions given:

https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1062

https://github.com/symfony/symfony/issues/7291

PHP Warning: simplexml_load_file(): I/O warning : . repositories , I am trying to: Debug the cause of this error: PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity. If you do a Google search on "failed to load external entity symfony" or "failed to load external FosUserBundle" you will find quite a few people having issues due to Doctrine mapping failed to load xml mapping (mostly of FosUserBundle).

simplexml_load_file(): I/O Magento warning : failed to load external , 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​  PHP's SimpleXMLElement extension is unable to load the XML file. This is due to the XML in that file. As you have not shown the XML, there is not much more that can be said about it as you haven't even shared your level of understanding as well nor which software (Magento, PHP) and library versions (libxml) has been used.

Repeated warning: "simplexml_load_file(): I/O warning : failed to , Repeated warning: "simplexml_load_file(): I/O warning : failed to load external entity "/xml/Menu/Activity.xml". Environment: Observed in Civi  Latest Drush 8.x with PHP 5.6.7 (Debian Jessie, Apache2, fresh Drupal 7 minimal install) causes simplexml_load_file(): I/O warning : failed to load external entity "" Project.php:72 Failed to get available update data from https://update

Fixing PHP's 'Warning: simplexml_load_file(): I/O warning : failed to , parses an external XML file which it loads using simplexml_load_file. simplexml_load_file(): I/O warning : failed to load external entity'. I'm facing a very strange issue with Drush wget and OpenSSL on my mac book (MacOSX Sierra). When I launch drush make site.make command (which should theoretically download the all modules) it fail

Comments
  • Beside the fact you change vendor which is bad, adding an @ to hide a fatal error is worse, your php script stops and you don't even realize it, it will look fine without error but you will notice some weird behavior after that without knowing why.
  • Yes, i'm aware that this quickfix is not a solution, but it's better than nothing !