PHP fgets()无法从同一IP上的域获取

时间:2012-05-25 12:20:32

标签: php shared-hosting addon-domain

我正在尝试对在同一个共享主机帐户下托管的所有网站执行基本的正常运行时间监控。我想将网络问题与本地(服务器负载)问题隔离开来,因此我无法使用外部正常运行时间监控器。

以下php脚本可以轮询托管在其他IP地址上的网站,但不是它自己的网站。我可以和我一起通过SSH控制台从我的主要和附加域(所有相同的IP)卷曲,但我似乎无法通过PHP执行相同的环回操作。为什么呢?

<?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);
        }
    }
}
?>

0 个答案:

没有答案
相关问题