Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Warning: DOMDocument::load(): I/O warning : failed to load external entity

I read everything I could about this error without being able to find any solution.

I have a simple page that looks like this:

$xmlfile = "/var/www/marees.xml"; //Fichier dans lequel récupérer les données
$ent = new DOMDocument();
$ent->load($xmlfile);

if(!(@$ent->load($xmlfile)))
{
    echo "Unable to load : " . $xmlfile;
    exit();
}

I get three times out of four, randomly this error:

PHP Warning: DOMDocument::load(): I/O warning : failed to load external entity "/var/www/marees.xml" in /var/www/marees/test2.php on line 7

When I restart Apache, the script works fine for 5 minutes, then the error starts to appear.

XML file weighs 595 kB, is present and readable.

What might be the problem?

like image 260
MichaelED17 Avatar asked May 06 '14 08:05

MichaelED17


2 Answers

add this command to the top of your script:

libxml_disable_entity_loader(false);

For more details see this link.

like image 180
Eric Tully Avatar answered Nov 18 '22 12:11

Eric Tully


public mixed DOMDocument::load ( string $filename [, int $options = 0 ] )

The function declaration carries with it an optional parameter named $options where:

options
Bitwise OR of the libxml option constants.

The usage of the LIBXML_NOWARNING constant solves the issue for me:

$ent->load($xmlfile, LIBXML_NOWARNING);
like image 36
fantaghirocco Avatar answered Nov 18 '22 12:11

fantaghirocco