FOSUserBundle exception

Created on 27 Mar 2013  路  24Comments  路  Source: FriendsOfSymfony/FOSUserBundle

First, thanks for the project!

im getting this exception sometimes, but i cant simulate:

ErrorException: Warning: simplexml_load_file(): I/O warning : failed to load external entity "/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/doctrine/User.orm.xml" in /vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php line 706

thanks!

Most helpful comment

Well, I was searching for a solution and I concluded that the problem is the bug (or feature?) indicated by @matts2cant two years ago: https://bugs.php.net/bug.php?id=64938

The function 'libxml_disable_entity_loader' is not thread safe so, if a thread configure it to 'true' all the others threads are true too. And it should be at 'false' by default when a new request come. That is why the problem disappears when we restart php-fpm daemon.

If you write this at the beginning of app.php we can see that all is working again:

<?php
// app.php
libxml_disable_entity_loader(false);

The problem is caused by some third-party bundle or library, because it must be changing to true and is not restoring to false again.

All 24 comments

The exception does not come from FOSUserBundle but from simplexml used in the Doctrine code.

I suspect it may be the same issue than https://github.com/symfony/symfony/issues/7291 : a buggy libxml2 version. Can you check the version you use ?

And the path to the file used is weird. Is your vendor folder really at the root of the filesystem or did you strip some part ?

yes i removed the project name.

the version of libxml 2.8.0, you know if there is a way to fix it?

very thks! @stof

I reinstalled and it worked! Thanks!

Just letting random folks know that this issue still exists. I encountered the same issue on debian with version 2.7.8 of libxml2 ; subsequently, I downloaded the latest (2.9.1), compiled, installed ( & re-compiled php with the new library). Unfortunately, this did not solve the issue for me. I wish I were better at debugging so I could locate the precise cause of the error, still struggling to find a solution, though.

The weirdest thing is that it only _sometimes_ fails - roughly on 75% of page queries within symfony.

I hate leaving a comment on a closed ticket, but I'm concurring with @esperandus. I'm having this same problem, too. I have updated my libxml2 on Debian 7 using backports. I can reproduce the problem reliably... it happens when my application receives a pubsub notification. All subsequent requests (and notifications) fail with this error. Upgrading libxml2 doesn't fix it for me.

Just leaving a comment to mention I'm having the same issue, it was occurring every other page load, and now it's constantly. The file it's trying to load is formatted correctly, exists, and has the correct permissions. My libxml version is 2.9.1.

Same issue here. My app crashes about 50% of the time. When i restart php5-fpm, it goes away ... and comes back after a few minutes.

Here are some links i found that seems to be related :
https://bugs.php.net/bug.php?id=64938
https://bugs.php.net/bug.php?id=62577

Don't know if it helps.

FYI, I found a quick workaround that fixes it, just enable the metadata_cache_driver in doctrine with apc, memcache or any other caching system. Doctrine will only parse the "User.orm.xml" file once and it will be cached for all the following requests. Of course it doesn't fix the bug itself, but it can save you if you encounter this problem in production.

Here is the config i use:

doctrine:
    orm:
        entity_managers:
            default:
                metadata_cache_driver:
                    type: memcache
                    host: localhost
                    port: 11211
                    instance_class: Memcache
                query_cache_driver:
                    type: memcache
                    host: localhost
                    port: 11211
                    instance_class: Memcache

Hope it helps :)

anyone has found a solution?

Same issue!

same here. i understand that this might be the problem of libxml but it looks like its related only to User.orm.xml
everything was perfectly fine until now. i've done composer update and brew updated and im getting this error on every 2nd, 3rd request
its getting to the point that FOS is unusable for me
would it be possible to revisit this file and do some testing?
transforming model configuration into YML would solve these problems!!

+1
Tried different versions of libxml2 and nothing helped. Still don't know how to solve this issue.
@stof maybe you will know which version of libxml2 will work fine with fosub?

i've reinstalled basically everything and im not getting the error, for now.
but i have couple of 'tricks' to try once this happen again, feel free to try it and report here, looks like no1 competent is reading it anyways.
the error is in class XmlDriver in function loadMappingFile, just search for it in your editor. possible solution could be to simply skip the whole file loading via simplexml_load_file.
you can try to harcode the output of User.orm.xml into simplexml_load_string.
(this 'might' work as im getting i/o error and by doing this you would essentially eliminate doing additional i/o. but who the hell knows whats going on in there anyways)
other option, much much complicated, would be to try bypass any xml manipulation by harcoding the whole xml data into php class and use this as return of loadMappingFile or maybe even earlier.
good luck and patience be with you and your descendants (fcking XML, everyone should use json or yml anyways)

QuickFix in XmlDriver.php Line 707

$xmlData = file_get_contents($file);
$xmlElement = simplexml_load_string($xmlData);

I encountered this error when running another PHP app (piwik) on the same php-fpm socket as my symfony2 application. It turned out that piwik had some kind of side-effect on le symfony2 application. We then created 2 different php-fpm sockets and it worked perfectly.

after some observation i've come to conclusion that libxml_use_internal_errors and libxml_disable_entity_loader turn some switch in libxml what persist across php requests. that means, that once i've encountered this error, the only thing what solve it was restarting php-fpm

I'm having this bug in our dev server lately, it shows randomly, but not in prod. Nobody seems to have a solution for this, but you talking about it being fixed but how? changing vendor to
XmlDriver.php Line 736
$xmlData = file_get_contents($file);
$xmlElement = simplexml_load_string($xmlData);

is not really an option, reinstalling libxml2 or updating didn't work neither.

Thanks for any input that may help.

I have the same probelm, but not in production environment.

Any solution ?

Thank you.

Run into this problem today. No idea why it turns up after running for more than half year.

Well, I was searching for a solution and I concluded that the problem is the bug (or feature?) indicated by @matts2cant two years ago: https://bugs.php.net/bug.php?id=64938

The function 'libxml_disable_entity_loader' is not thread safe so, if a thread configure it to 'true' all the others threads are true too. And it should be at 'false' by default when a new request come. That is why the problem disappears when we restart php-fpm daemon.

If you write this at the beginning of app.php we can see that all is working again:

<?php
// app.php
libxml_disable_entity_loader(false);

The problem is caused by some third-party bundle or library, because it must be changing to true and is not restoring to false again.

@sgomez Good job. I think this is true.

I'm experiencing this problem too. As @sgomez correctly noted, the problem occurs when another thread sets libxml_disable_entity_loader(true). So if you have another app on the same server which sets libxml_disable_entity_loader(true), you'll eventually run into this problem.

In our case, the problem was caused by Phabricator. After restarting php-fpm, everything is fine until someone accesses Phabricator, which then sets libxml_disable_entity_loader(true), causing this error to occur in our Symfony app, due to thread sharing.

So there are 2 possible solutions:

  1. Find out which app is setting libxml_disable_entity_loader(true), and move it onto another server, or,
  2. In your web/app.php file, add the following code as suggested by @sgomez :
<?php
// app.php
libxml_disable_entity_loader(false);

Having this issue too, on my server it is relating to tt-rss (https://tt-rss.org) on the same PHP server setting libxml_disable_entity_loader to true. To fix this, I changed line 814 of Doctrine's XmlDriver.php (doctrine\orm\lib\Doctrine\ORM\Mapping\Driver\XmlDriver.php)
from: $xmlElement = simplexml_load_file($file);
to: $xmlElement = simplexml_load_string(file_get_contents($file));

Not sure how to raise issue in Doctrine's project to get this looked at.

Posted to doctrine-user Google+ group:
https://groups.google.com/forum/m/#!topic/doctrine-user/vAb_3zcz6vU

Was this page helpful?
0 / 5 - 0 ratings