3

How reliable is get_headers() for checking if a site is online?

Basically:

    $check = get_headers($url,1);

So again how reliable is it and can I depend on its accuracy?

joejam
  • 265
  • 2
  • 6
  • possible duplicate of [curl and ping - how to check whether a website is either up or down?](http://stackoverflow.com/questions/4607684/curl-and-ping-how-to-check-whether-a-website-is-either-up-or-down) – Alternatex Oct 08 '14 at 13:20
  • I know of other methods. My question is how reliable is get_headers(); – joejam Oct 08 '14 at 13:30
  • I always find reading the discussion at the bottom of the docs for the method is the best way to understand how reliable a function is. Or at least for getting started. – tbddeveloper Oct 08 '14 at 13:37
  • @joejam That is a difficult question to answer. I'd say generally it's not a good solution for checking if a site is online. The alternatives are better. Apparently it's very slow since it uses a GET instead of a HEAD request and it also follows HTTP redirects appending new headers to the array. Not sure what I can say on reliability, it's best to judge for yourself. – Alternatex Oct 08 '14 at 13:38

1 Answers1

0

If you want to use the results of get_headers() for input to any other function I would not count on 100% accuracy. If you want to look at the results with your own eyes (like I do) and fix or check any discrepancies yourself, then this will be fine.

The results can be effected by a number of things for both get_headers() and cURL. Personally I run cURL against an array of all the websites I manage at least once a day while I am at work and typically I get a few false negatives. I used to use the get_headers() method, but in terms of false negatives I didn't notice any difference. The reason I switched to cURL was it gave better options in terms of returning error messages etc.

NOTE: If, like me, you are running this against an array of sites you manage I should point out that on many occasions this approach has caused me to get sucked into the blacklist from my hosting provider because I was running this at the same time that they were detecting a brute force attack from elsewhere. Some phone calls to tech support and after a few weeks they began recognize me when I called... not a good thing.

KnightHawk
  • 901
  • 9
  • 18