检查服务器可用性

时间:2014-04-08 08:05:17

标签: php fsockopen

尝试从数据库获取地址并写入数组,但总是说Bad,所有服务器都可用。

include('config.php');
$query_select = "select `ip` from `server`";
$result_select = mysql_query($query_select);
$host=array();
while($row = mysql_fetch_array($result_select,MYSQL_ASSOC))
{
    foreach ($row as $r){
       $host[$r] = $r;
     }
}
foreach ($host as $h){
    $waitTimeoutInSeconds = 1; 
        if($fp = fsockopen($h,$waitTimeoutInSeconds)){   
              echo 'good';
        } else {
              echo 'bad'; 
                } 
fclose($fp);
}

0 个答案:

没有答案