
I recently found this neat dashboard company called leftronic and they provide a way for you to push data to their dashboard and customize it they way you want. So what I did was I decided to set up a service status page for my gaming forum so that the users will know if something goes down. Well as a result I came up with this really neat way of check if a service is running on a certain port.
Hopefully this can come in handy 🙂
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php $host = 'yoursite.com'; $ports = array( 80 => 'Apache', 110 => 'POP3', 3306 => 'MySQL' ); //----------------------------------------- // Check all services //----------------------------------------- foreach ( $ports as $port => $service ) { $connection = @fsockopen($host, $port,$errno, $errstr, 3); //----------------------------------------- // Test if we can connect //----------------------------------------- if ( is_resource($connection) ) { echo "{$host}:{$port} ( {$service} ) is open."; fclose($connection); } else { echo "{$host}:{$port} is not responding..."; } } |
This was a quick and easy way to test services on different ports 😀