0

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 time outs, but if the page is not found (404) I would like to add it to a list of not found pages.

If I could differentiate between the two types of errors I can 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 I wanted to do curl worked out better.

hakre
  • 193,403
  • 52
  • 435
  • 836
Rob
  • 2,332
  • 7
  • 31
  • 35
  • possible duplicate of [Easy way to test a URL for 404 in PHP?](http://stackoverflow.com/questions/408405/easy-way-to-test-a-url-for-404-in-php) – hakre Jun 24 '13 at 01:27

1 Answers1

3

I think you would have to use curl for that. Curl can tell you if the request timedout or returned a 404. If neither of these happened you could just feed the results of the request to simplexml_load_string.

http://nl2.php.net/curl

Pim Jager
  • 31,965
  • 17
  • 72
  • 98