0

I am trying to perform basic uptime monitoring for all my websites hosted under the same shared hosting account. I want to isolate network issues from local (server load) issues, so I cant use an external uptime monitor.

The following php script can poll sites hosted on other IP addresses, but not it's own. I can wget & curl from my primary and add-on domains (all same IP) via an SSH console, but I cant seem to do the same loopback operation via PHP. Why?

<?php
check('some-other-host.com', 'validation text 2'); //succeeds
check('addon-domain-on-same-host.com', 'validation text 1'); //fails
// other sites go here //

function check($host, $find) {
    $fp = fsockopen($host, 80, $errno, $errstr, 10);
    if (!$fp) {
        echo "$errstr ($errno)\n";
    } else {
        $header = "GET / HTTP/1.1\r\n";
        $header .= "Host: $host\r\n";
        $header .= "Connection: close\r\n\r\n";
        fputs($fp, $header);
        while (!feof($fp)) {
            $str .= fgets($fp, 1024);
        }
        fclose($fp);
        if (strpos($str, $find) == false) {
            echo $host." is down. ";
            mail('me@mine.com', $host.' is down.', $str);
        }
    }
}
?>
harvest316
  • 1,401
  • 14
  • 21
  • 1
    It might be a routing issue. My dedicated server suffers from a similar issue where when trying to access the domain name of a site it hosts, it fails, but if I use the IP address, or set an entry in the hosts file, it works... I think it's related to the internal DNS of your server. – Gavin May 25 '12 at 12:24
  • What exactly does "fails" mean? Does the server blow up? Do you get an error message? What exactly is your definition of not working? – Berry Langerak May 25 '12 at 12:36
  • By "fails" I mean that I get the email saying said host is down. – harvest316 May 27 '12 at 11:35
  • This might help: I added an `echo $str;` line to see what we got back, and it's a 403 Permission Denied. – harvest316 May 27 '12 at 11:38

0 Answers0