Hey Guys,
I have the following script to check if my webserver listens on port 80 + how long it took to response:
<?
$conn = mssql_connect('localhost','user','pass');
mssql_select_db("monitoring");
//start_time
list($sec, $usec) = explode(" ", microtime());
$timestart = $sec + $usec;
$fp = fsockopen("139.23.2.230", 80);
if (!$fp)
{
$sql = "INSERT INTO http (status) VALUES (0)";
mssql_query($sql);
mail("kersten.lohmeyer@siemens.com","Status Webserver","ALARM! - webserver down!");
} else {
//end_time
list($sec, $usec) = explode(" ",microtime());
$timeend = $sec + $usec;
$time = $timeend - $timestart;
$time = number_format($time,3);
fputs($fp, "GET / HTTP/1.0\r\n\r\n");
$string = fgets($fp,128);
fclose($fp);
if (!strstr($string,"HTTP/1.1 200 OK"))
{
$sql = "INSERT INTO http (status) VALUES (0)";
mssql_query($sql);
mail("kersten.lohmeyer@siemens.com","Status Webserver","ALARM! - Nicht erreichbar!");
}
echo $string;
$sql = "INSERT INTO http (responsetime, status) VALUES ($time, 1)";
mssql_query($sql);
if($time >= 0.030)
{
mail("kersten.lohmeyer@siemens.com","Status Webserver","ALARM! - too slow!");
}
}
mssql_close($conn);
?>
My Problem is, if I stop the apache service on my win2k machine, php can still connect to port 80, because windows does not close port 80 completely, cause somewhere there are still some people having a browser window open, which prevents win2k to close port 80 completely.
Now I tried sending GET / HTTP/1.0\r\n\r\n to the server, to get a response. If I get an answer like HTTP/1.1 200 OK then the server runs, if not, then not. But this doesn't work either.
Any suggestions?
TIA
Kersten