With simplexml_load_file I would like to distinguish between timeout and 404 errors

I am currently using:

$page = simplexml_load_file('http://www.example.com/page.html');

      

In my code, I would like to retry if the page is missing, but if the page is not found (404), I would like to add it to the list of not found pages.

If I could distinguish between the two types of errors, I could do the rest.

For the curious, you can get the status code with the following code:

if ($page == FALSE) 
{
  list($version,$status_code,$msg) = explode(' ',$http_response_header[0], 3);
  echo 'Status Code: '.$status_code."\n";

   ...

      

But for me to want to do the curl it worked better.

0


a source to share


1 answer


I think you will have to use curl for this. Curl can tell you if the request timed out or returned 404. If none of these happened, you can simply feed the query results to simplexml_load_string.



http://nl2.php.net/curl

+3


a source







All Articles