Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

"Site is down" in function to check backlinks



7:22 pm on Jul 1, 2007 (gmt 0)

10+ Year Member


I am using a function to check my backlinks. The function halts for a long time (about 10 seconds) when one of the sites I want to check is down. Is there a way I can specify that when the site does not load after 5 seconds I generate a message "site is down"? How can I do this?

Here is the function

function check_back_link($remote_url, $your_link) {
$match_pattern = preg_quote(rtrim($your_link, "/"), "/");
$found = false;
if ($handle = @fopen($remote_url, "r")) {
while (!feof($handle)) {
$part = fread($handle, 1024);

if (preg_match("/<a(.*)href=[\"']".$match_pattern."(\/?)[\"'](.*)>(.*)<\/a>/", $part)) {$found = true; break;}
return $found;


9:45 pm on Jul 1, 2007 (gmt 0)

5+ Year Member

Just a thought, are you sure its the script thats hanging, rather than the failed request to the webpage thats taking the time?

I know sometimes when I type a bad URL or whatever, the browser can take a while to return an error code...


8:03 am on Jul 2, 2007 (gmt 0)

10+ Year Member

@darreng: you're correct. It's not the script that's hanging. It's the page load that's taking to long because the page is not available.

That's why I want to limit the time the script needs to open the page. If the page does not load after e.g. 5 seconds I want to show an error message "Page not available". Is this possible?



11:12 am on Jul 2, 2007 (gmt 0)

5+ Year Member

Ah right sorry, I see what you mean now!


11:18 am on Jul 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

The PHP.net manual has got the following example, it might be useful on your case:

$timeout = 3;
$old = ini_set('default_socket_timeout', $timeout);
$file = fopen('http://example.com', 'r');
ini_set('default_socket_timeout', $old);
stream_set_timeout($file, $timeout);
stream_set_blocking($file, 0);
//the rest is standard


Featured Threads

Hot Threads This Week

Hot Threads This Month