Istalantar Posted April 8, 2015 Share Posted April 8, 2015 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 More sharing options...
justsomeguy Posted April 8, 2015 Share Posted April 8, 2015 If you're running that from the command line then I guess PHP might be ok, it wouldn't time out at least. Link to comment Share on other sites More sharing options...
Istalantar Posted April 9, 2015 Author Share Posted April 9, 2015 (edited) 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 April 9, 2015 by Istalantar Link to comment Share on other sites More sharing options...
justsomeguy Posted April 9, 2015 Share Posted April 9, 2015 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 More sharing options...
Christopher.Burkhouse Posted April 9, 2015 Share Posted April 9, 2015 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. http://php.net/manual/en/info.configuration.php#ini.max-execution-time -Chris Link to comment Share on other sites More sharing options...
Istalantar Posted April 11, 2015 Author Share Posted April 11, 2015 Unfortunatelly if have no own server to switch on and off, but at the moment i am a little inhibited anyway, so I can't try to much, but thank you so far. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now