homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

"Site is down" in function to check backlinks

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


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)

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)

@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)

Ah right sorry, I see what you mean now!


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

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


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved