Port Scanning and Service Status Checking in PHP
By Akash Mehta2008-06-06
Introduction
While building web applications, it's often important to keep an eye on the other services running on your server. Having access to the current status of public servers can empower your applications to make decisions and respond to problems automatically. Acknowledging a service is offline can also save endless support emails. In this tutorial, I'll show you how to keep track of your server status by scanning ports on your server with PHP.
What is server status?
A web application runs on a web server, such as the Apache HTTP server. However, your website often relies on many other "servers" on the same physical server - for example, your email servers, or your database server. Server status checking is commonly found in web hosting control panels, where it is crucial to be aware of the status of services:
Each of these services running on the server is listening on a particular port. We can easily check if the service is online by checking if it is still listening on that particular port. Should it be offline for any reason, we will simply receive no response on that port.
You will be familiar with a simple manual approach for checking the Apache HTTP server - the server by default listens on port 80; if it is offline, a web browser attempting to connect to it will receive no response and will display an error message to the user. You can check your websites are online by attempting to visit them in a web browser. In this tutorial, we will simply automate this process and develop a powerful means for examining server status at a glance.
Tutorial Pages:
» Introduction
» Service Checking 101
» Our Implementation
» Advanced Status Checking
