我正在尝试对托管在同一共享主机帐户下的所有网站执行基本的正常运行时间监控。我想将网络问题与本地(服务器负载)问题隔离开来,所以我不能使用外部正常运行时间监视器。
以下 php 脚本可以轮询托管在其他 IP 地址上的站点,但不是它自己的。我可以通过 SSH 控制台从我的主域和附加域(所有相同的 IP)wget & curl,但我似乎无法通过 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);
}
}
}
?>