jhines2000
asked on
FSockOpen() Too Slow!
Hi everyone, I will start with what I wanted to do, and how I am doing it- maybe someone can help me re-invent the wheel.
I had an idea < dangerous > and wanted to write a small network monitoring system. I succeeded! The software written looks at servers and specifically open ports running on servers, ie 1433 is MS Sql server, port 1677 is Groupwise POA, etc...
Using PHP and fsockopen() function, I am able to check to see if the host is alive, the port is open, etc... It works great when everything is up. When systems are down, the page refresh is god-awful slow. I set the timeout on the FSockOpen to 1 second, and the load time for the page is sometimes 15 to 30 seconds.
Here is the snippet of code from the PHP application:
while ( $row = mysql_fetch_array($result) ) {
$sysid = $row["sysid"];
$hostname = $row["hostname"];
$port = $row["port"];
$hostdesc = $row["hostdesc"];
$sockpointer = fsockopen($hostname,$port, $errno,$er rstr,1);
if($sockpointer) //check that it returns a value, if true, then host/port is alive, if false, host/port is dead.
{
//do some stuff- found an open port
fclose($sockpointer); //close port
} //end if
else
{
//do some stuff- found dead port
} //end else
flush(); //flush the socket
} //end while
$hostname, $port are values from a MySQL database getting shoved into this function
As I have said, the program is lightning fast when all servers are up, just sloooow when they do not respond. The 1 second timeout doesn't seem to change this delay either. I had tried different values all together.
This all being said- is there a faster way to accomplish what I am looking to do? Is my while loop structure horribly written- I am only a novice PHP scripter. Any help is much appreciated.
Along with the 250 points, I will gladly mention anyone who helps out in my PHP headers. I plan to release this tiny code on the internet to sites as hotscripts.com etc....
thanks!
I had an idea < dangerous > and wanted to write a small network monitoring system. I succeeded! The software written looks at servers and specifically open ports running on servers, ie 1433 is MS Sql server, port 1677 is Groupwise POA, etc...
Using PHP and fsockopen() function, I am able to check to see if the host is alive, the port is open, etc... It works great when everything is up. When systems are down, the page refresh is god-awful slow. I set the timeout on the FSockOpen to 1 second, and the load time for the page is sometimes 15 to 30 seconds.
Here is the snippet of code from the PHP application:
while ( $row = mysql_fetch_array($result)
$sysid = $row["sysid"];
$hostname = $row["hostname"];
$port = $row["port"];
$hostdesc = $row["hostdesc"];
$sockpointer = fsockopen($hostname,$port,
if($sockpointer) //check that it returns a value, if true, then host/port is alive, if false, host/port is dead.
{
//do some stuff- found an open port
fclose($sockpointer); //close port
} //end if
else
{
//do some stuff- found dead port
} //end else
flush(); //flush the socket
} //end while
$hostname, $port are values from a MySQL database getting shoved into this function
As I have said, the program is lightning fast when all servers are up, just sloooow when they do not respond. The 1 second timeout doesn't seem to change this delay either. I had tried different values all together.
This all being said- is there a faster way to accomplish what I am looking to do? Is my while loop structure horribly written- I am only a novice PHP scripter. Any help is much appreciated.
Along with the 250 points, I will gladly mention anyone who helps out in my PHP headers. I plan to release this tiny code on the internet to sites as hotscripts.com etc....
thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I havent been able to figure this out yet. I am going to abandon this question.
ASKER
Still not working as fast as it could be. Are there any other ideas out there?