I needed a function that tells me whether a certain web page is online or not. Nothing more, nothing less. Now I've a nice little kinda-working function like this:
[FONT=courier new]
function isOnline(address, port) {
$fp = fsockopen($address, $port, $errno, $errstr, 5);
if ($fp) { fclose($fp); return true; }
else { return false; }
}
[/FONT]
The problem is...I need to check several web-site statuses in a row and it takes a great deal of time every time I run the task. All sites are in the same 10Mbit LAN so the checking could be performed rapidly in theory. It would be enough if fsockopen() used just 1 second or so trying to connect one address (if not connected in that time site is considered to be offline) but no matter how low I set the timeout, it always takes way too long... :/
So, is timeout the right way at all to deal with this? Or is there a workaround or some solutions suggestions to my problem? OR...maybe a totally different approach to the whole problem?
(System config: WinXP, PHP v4.2.1, Apache v1.3.24)
Thanks in advance...