2010-12-09 29 views
0

je charge le fichier du serveur:php: l'état du serveur de contrôle simplexml_load_file

$url = 'http://www.sample.com/test.xml'; 
$xml = simplexml_load_file($url); 

Et si les serveurs est proche, j'obtiens l'erreur:

Warning: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed:... 
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity 

comment vérifier si le fichier est atteint?

Répondre

2

De l'manual page for simplexml_load_file

Returns an object of class SimpleXMLElement with properties containing the data held within the XML document. On errors, it will return FALSE .

ce qui signifie que vous pouvez faire

$url = 'http://www.sample.com/test.xml'; 
$xml = simplexml_load_file($url); 

// check what was returned 
if(FALSE === $xml) { 
    echo 'could not open file'; 
}