Jump to content

Server Status Page?


God of Ikiliki

Recommended Posts

This is something like what I've used:
[code=php:0]
$server = "google.com";
$port = 80;
$timeout = 1;
$isitalive = @fsockopen($server, $port,$errno,$errstr,$timeout);
if(!$isitalive) { echo "Server is down"; }
else { echo "Server is up"; }
[/code]

Just don't go crazy with this stuff. Using PHP fsock functions too much on shared hosting will usually get you kicked off pretty fast, because of CPU usage.


The MySQL tutorial was linked to because you asked about storing servers. A database would be best for that.
Link to comment
https://forums.phpfreaks.com/topic/35081-server-status-page/#findComment-165741
Share on other sites

One thing I've found is the server may respond... however its not healthy and might as well be down...

For example.. if you put in http://www.mydomain.com and it comes up as an apache error cause by a bad config file.  Or your mysql database is not working so your page comes up but nothing works so it might as well be shot.

You could have them create a page called server_check.php  which contains a read from the database.

Then you call their site..
[code=php:0]
$page_to_check = 'http://www.mytesthost.com/server_check.php';
$check_page = file_get_contents($page_to_check);

if($check_page != 'The page worked, the db val is 345.') {
    $result = 'host is down';
}
else {
    $result = 'host is up';
}
[/code]

This should be a little more valuable.
Link to comment
https://forums.phpfreaks.com/topic/35081-server-status-page/#findComment-165747
Share on other sites

  • 3 weeks later...
Continuing what Hypnos said you can have something like this :

[code]
$server= $_GET[ip];
$port = $_GET[port];
$timeout = 1;
$isitalive = @fsockopen($server, $port,$errno,$errstr,$timeout);
if(!$isitalive) { echo "Server is down"; }
else { echo "Server is up"; }[/code]

The url to the file will look something like
[code]status.php?ip=127.0.0.1&port=80[/code]

If you had checks to see if an ip or port was entered you can use this page. If you don't enter an ip or port the page shows an error and won't work.
It's untested, so give it a try  ::)
Link to comment
https://forums.phpfreaks.com/topic/35081-server-status-page/#findComment-179794
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.