timing out a for loop, fopen
| From: | ROBERT MCPEAK | Date: | Wed, 15 Jan 2003 21:34:38 +0000 |
| Subject: | timing out a for loop, fopen | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-131767@lists.php.net to get a copy of this message | ||
Dear PHP Gurus:
I'm looking for a way to timeout an fopen function. I'm doing some link checking inside
of a for loop and some links "hang" rather than return a definitive "can't
connect" or "can connect." (Pardon the highly technical jargon there...)
In cases where my link hangs, I'd like to simply display a message (i.e., "hanging")
and advance to the next loop.
I have search the docs/forumns far and wide and can't find anything definitive. As far as I
can tell socket_set_timeout won't quite do what I want it to.
Any ideas? Here's the important part of my code:
for ()
{
echo "Checking: $link : \n"; flush();
$fp = @fopen($link, "r");
if (!$fp) { echo "<font class=linksred>The link is dead!</font>"; }
else { fclose($fp); echo "<font class=linksgreen>The link is
working!</font>"; }
echo "<br><bR>";
echo "</font>";
}
Thanks in advance!