Reputation: 541
So I'm trying to do a admin panel and also show the status of all the different services.
In order to accomplish that I use a function to see if ports respond or not.
Here is the code:
public function getPort($ports, $host = NULL) {
if (!$host) { $host = "somesite.com"; }
$ports = array($ports);
foreach ($ports as $port) {
$connection = @fsockopen($host, $port);
if (is_resource($connection)) {
return "<span class=\"label label-success\">Online</span>";
fclose($connection);
} else {
return "<span class=\"label label-danger\">Offline</span>";
}
}
}
Ports like port 80 and 21 appear as online but not ports like 3306 for MySQL or 9987. Is there any way for me to first check why it is like this and then also solve this so it appears as online?
Upvotes: 0
Views: 29
Reputation: 6534
By default, MySQL's 3306 port is only available on local IP address – 127.0.0.1, so if you are testing the port from outside the machine, it will appear as closed.
If you want to monitor your services from another machine, ensure your firewall allows that and ensure your services are listening on global IP addresses, not 127.0.0.1 (you can do a simple netstat -an |grep LISTEN
to verify that).
Upvotes: 1