I am trying to implement a PHP script that will ping an IP on a specific port and echo out whether the server is online / offline. This way, users will be able to see if non-access to the server is a server fault or a own network problem.
The site is currently on http://Dev.stevehamber.com. You can see the “Online” is wrapped in a class of ‘PHP’ and I need this to reflect if the server is online or offline. The application runs on port TCP=25565 so I need the output to show if this port is reachable or not.
Here is a snippet I found that is (I suppose) what I’m looking for:
<?php
$host = 'www.example.com';
$up = ping($host);
// if site is up, send them to the site.
if( $up ) {
header('Location: http://'.$host);
}
// otherwise, take them to another one of our sites and show them a descriptive message
else {
header('Location: http://www.anothersite.com/some_message');
}
?>
How can I replicate something like this on my page?
Based on the comments on the question,
fsockopen()is the simplest and most widely available way to accomplish this task.Note that all this does is test whether the server is accepting connections on TCP:25565. It does not do anything to verify that the application listening on this port is actually the application you are looking for, or that it is functioning correctly.