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

I read everything I could about this error without finding a 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, accidentally this error:

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

When I restart Apache, the script works fine for 5 minutes, an error appears.

The XML file weighs 595 kB, is present and readable.

What could be the problem?

+6
source share
2 answers

add this command to the top of the script:

 libxml_disable_entity_loader(false); 

See this link for more details.

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

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

options
Bitwise OR libxml option constants .

Using the constant LIBXML_NOWARNING solves the problem for me:

 $ent->load($xmlfile, LIBXML_NOWARNING); 
+1
source

All Articles