Quote:
Originally posted by cbe
Hello,
I was wondering if someone could help me.
I am using a php script to show whether another server is online
and when the server "is" down it takes forever to load the page.
the first script I used first used ping and it was quite fast, but since I moved servers they dont allow ping - ping has to be run as root.
so I tried a few different things till I settled with this script:
<?php
$fp = fsockopen ("IP.address.of.server", 80);
if (!$fp) {
?>
<b>Server is Offline</b>
<?
}
else
{
?>
<a href="http://address">Link is UP</a>
<?
}
?>
Is there a better or faster way to do this? or am I stuck?
the script above resides on a Cobolt Raq if that would help.
Thanks for any help you can provide,
Cbe
|
I see that u are trying to open a socket connection to port 80 for all these servers, and I might point out, that if you are intending to monitor the state of webservers on this machine, then that is great, but a a webserver could be down, and the machine still be up. I only point this out, because it is completely different than what the ping program does, since that uses icmp, which is not directly or indirectly supported from within php.
Nevertheless, your best chance for speeding up the page is to attempt to shorten the blocking that occurs when you hit a server that is down, and the webserver sits waiting for a connection that is not going to work. Notice the last paramter on the fsockopen call? Set that to 1 for 1 second, and a connect attempt will timeout after 1 second.
int fsockopen (string [udp://]hostname, int port [, int errno [, string errstr [, double timeout]]])