Jump to content

Serverstatus script - looking for feedback


Istalantar

Recommended Posts

Hello, I came up with this script to inform me when a certain server is going online. I am not sure if php is the best choice here, so what do you think?

<?phpecho "Script started.";$fp1 = fsockopen($ip1, $port1, $errno1, $errstr1, 2);$fp2 = fsockopen($ip2, $port2, $errno2, $errstr2, 2);$fs1_sent = 0;$fs2_sent = 0;while(!$fp1 or !$fp2){echo "Last update".date("H:i:s");if (($fp2 = fsockopen($ip2, $port2, $errno2, $errstr2, 2)) and $fs2_sent == 0) {mail($_POST[mailaddr], $subject1, " ");$fs2_sent = 1;}if (($fp1 = fsockopen($ip1, $port1, $errno1, $errstr1, 2)) and $fs1_sent == 0) {mail($_POST[mailaddr], $subject2, " ");$fs1_sent = 1;}sleep(60);}?>
Link to comment
Share on other sites

Yesterday I ran it via browser (I wanna use the script from anywhere, and maybe let other people use it). After what time would it timeout, when I use it that way? And is there some way to test this script with a connection I can turn on and off?

Edited by Istalantar
Link to comment
Share on other sites

The default timeout for PHP is 30 seconds. The web server or browser might enforce its own timeout also. If you're controlling the servers that it's trying to connect to then you can bring them offline and back online to test.

Link to comment
Share on other sites

To answer your question about timeouts, I have the info below. The problem with the possibility of timing out is it provides a fatal error. So if the first server is out, you really can't check the other servers. The best method to correctly check all servers might be a mix of PHP and JS. Have JS load, for example, server.php?s=1 server.php?s=2 and server.php?s=3. If the file retrieval times out, the server is down. Or... I think that would work, right?

 

http://php.net/manual/en/function.set-time-limit.php

Please read all documentation before using this function. I say this since...

 

1. It doesn't work in safe mode

2. Does not affect the default in php.ini

3. Sets the timeout at the time of using the function. So if you use set_time_limit at the start of every fsockopen function, they will each have their own timeout

 

Something else to note:

 

 

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.

 

-Chris

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...