Hi I am trying to incorporate a function in my project that will ping my app servers and see if they are running or not. Problem is, everytime I try to use this function it always returns that they are alive, even though I am in my local environment, and there are no servers at those IP addresses. So whats going on?
Here is my function:
function ping($host, $port, $timeout) {
if($fp = fsockopen($host,$port,$errCode,$errStr,$timeout)){
return 'Alive';
} else {
return 'Not alive';
}
fclose($fp);
}
Here is how I am calling the function:
foreach ($appservers as $key => $value) {
echo ping($value['privateip'] , 80, 1).'<br/>';
}
Here is my array of server variables:
$appservers = array(
'app1' => array(
'publicdns' => 'app1.xxxx.com',
'privateip' => '1.1.1.101',
'alive' => NULL,
'active_users' => NULL
),
'app2' => array(
'publicdns' => 'app2.xxxx.com',
'privateip' => '1.1.1.102',
'alive' => NULL,
'active_users' => NULL
),
'app3' => array(
'publicdns' => 'app3.xxxx.com',
'privateip' => '1.1.1.103',
'alive' => NULL,
'active_users' => NULL
),
'app4' => array(
'publicdns' => 'app4.xxxx.com',
'privateip' => '1.1.1.104',
'alive' => NULL,
'active_users' => NULL
)
);