Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.