Server status check class
Today I had to make some updates to SM2’s hosting server-status module, which I admittedly built in a rush. The result is that I put a decent effort in this time, even going to the extent of researching HTTP and POP3 protocols to make sure I get the right return messages.
So, I have this funny feeling I’ll never have the necessity to update this, but here is Version 0.1 of the ServerCheck abstract class, which you’re welcome to take and do with it what you like (under the MIT license).
Example usage:
if (ServerCheck::pop('mail.ucantblamem.com')) {
echo 'Server is online!';
} else {
echo ServerCheck::error();
}
The class uses fsockopen() to test a server and the timeout is set to 2 seconds by default; if you want to change that, you can do that like so:
ServerCheck::set_timeout(3);
You can also override the default ports (which is 80 for web and 110 for pop) by specifying the second parameter:
if (ServerCheck::web('http://secure.heritageonline.com.au/', 443)) {
echo 'Server is online!';
} else {
echo ServerCheck::error();
}
This class is written as an abstract PHP 5 class, but if wouldn’t take too much effort to back-port it as a regular PHP 4 class if need be.
This class is very simple (hence the 0.1), so if you do use this class and add to it feel free to send it back my way; it would be nice to eventually have a really widely usable class compiled, which of course I’ll put on offer here.