I check wether a site site is up-and-running by checking for a HTTP 200 status code:
<?php
$url = 'www.proxyserver-demo.com';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if (200==$retcode)
{
echo "All's well";
}
else
{
echo "not so much";
}
?>
Every site I try however, even non-existing ones return 200 OK status without fail, which should not be possible in the case of the non-existing ones. (my code always outputs "All's well")
My OS is Centos linux, what could be the matter here?
sorry for abusing the answer field for what should probably be a comment but I can't really think of a way to present this info properly otherwise. I honestly don't know yet how to whip them comments into any properly displayed and formatted shape. :-|
Anyway, since your code should be working fine but for you it always retuns "everything OK" while you check for a HTTP response, it could be that your ISP is doing DNS-highjacking, which basically is returning fake ip-address data, redirecting you to their own server, usually for monetary gains under the guise of userfriendlyness. (ISP-page that shows "this page doesn't exist" combined with ads or the offer of services such as domain registration, etc..)
an easy way to test is just to ask for DNS data with an application like dig. A query to a properly functioning DNS server for a non-existing domain should return NXDOMAIN as its status:
so when we check for a totally fake domain
notexisting.fake
with the following command:dig A notexisting.fake.
, this is what it generally should give:as you can see,asking for this nonexisting domain
notexisting.fake.
returns usWhereas when we query for google.com, with
dig A google.com.
our query returns us the proper NOERROR
and returns us the ip address found for the A record
So if your query for the fake domain returns an ip address then you know the problem is with your DNS and your isp no doubt redirects every non-existing request to a server of their own, messing with your 'is my site up strategy' since you'll get a 200 OK status but it'll effectively be from an imposter.
If this is the case then you can only: