php:simplexml_load_file检查服务器状态

i load file from server:

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

And if servers is close i get error:

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

how to check if the file is reached?

From the 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.

which means you can do

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

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