Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checking if facebook is up or down help

    for some reason, i frequently can't connect to facebook (just facebook). not really sure what it is or why. but i'm trying to just have a personalized website where i can go to check it's up or down status.

    Code:
    <?php
           ini_set("default_socket_timeout","05");
           set_time_limit(5);
           $f=fopen("http://www.facebook.com","r");
           $r=fread($f,1000);
           fclose($f);
           if(strlen($r)>1) {
           echo("<span class='online'>Online</span>");
           }
           else {
           echo("<span class='offline'>Offline</span>");
           }
    ?>
    is what i'm working with. i've used and tested this script with other websites and it works a'ok. but when it comes to facebook, or some reason it won't work and i'm getting errors, such as:

    Code:
    Warning: fopen(http://www.facebook.com) [function.fopen]: failed to open stream: Redirection limit reached, aborting in /home/davidhoppus/public_html/supbr0.php on line 36
    
    Warning: fread(): supplied argument is not a valid stream resource in /home/davidhoppus/public_html/supbr0.php on line 37
    
    Warning: fclose(): supplied argument is not a valid stream resource in /home/davidhoppus/public_html/supbr0.php on line 38
    Offline
    thanks in advanced for the help.

  • #2
    New Coder
    Join Date
    Jul 2011
    Location
    USA
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    Why not use file_get_contents instead:

    PHP Code:
    <?php
    ini_set
    ("default_socket_timeout","05");
    set_time_limit(5);
    $f file_get_contents("http://www.facebook.com");
    if(
    strlen($f)>1) { 
    echo(
    "<span class='online'>Online</span>");
    } else { 
    echo(
    "<span class='offline'>Offline</span>");
    }
    ?>
    An even better way is to use curl if your server supports it:

    PHP Code:
    <?php
    $url 
    "http://www.facebook.com";
    $agent $_SERVER['HTTP_USER_AGENT'];

    $ch curl_init();
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_HEADERtrue);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLINFO_EFFECTIVE_URLtrue);
    curl_setopt($chCURLOPT_USERAGENT$agent); 
    $src curl_exec($ch);
    $extract curl_getinfo($ch);
    $httpcode $extract['http_code'];
    curl_close($ch);

    if(
    $httpcode >= 200 && $httpcode 303)
    {
    echo 
    "<font color=\"green\">Online</font><br>";
    }
    else
    {
    echo 
    "<font color=\"red\">Offline</font><br>";
    }
    ?>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •