SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict Phil-man's Avatar
    Join Date
    Nov 2000
    Posts
    291
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Use fopen to see if web site is down?

    Hi:

    I have a link to a site that, unfortunately, goes down with some frequency. So I'm trying to figure out how to check to make sure the site is up, and if so, display certain output (a frames page, actually), and, if not, redirect to a different site. Here's my code, with the "else" stuff stipped out for brevity's sake, and with the code commented out:

    <?php
    // $file=fopen("http://www.ticketslive.com/","r");
    // if(!$file) {
    // header("Location:http://www.tickets.com/venue_info.cgi?VENUE_ID=00000");
    // }
    ?>

    And here are the error messages I get:

    Warning: php_network_getaddresses: getaddrinfo failed: no address associated with name in /usr/home/v1/yadayada/html/performances/tickets_online.php
    on line 2

    Warning: fopen("http://www.ticketslive.com/","r") - Bad file descriptor in /usr/home/v1/yadayada/html/performances/tickets_online.php on line 2

    Warning: Cannot add header information - headers already sent by (output started at /usr/home/v1/yadayada/html/performances/tickets_online.php:2) in
    /usr/home/v1/yadayada/html/performances/tickets_online.php on line 4

    Am I missing something obvious? Is there another way that I should be trying to accomplish this same task? Thanks for any help!

  2. #2
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hum...

    I'm not sure how to do it the way you were thinking, but will this work for you?
    PHP Code:
    <?php
    $fp 
    fsockopen ("www.php.net"80$errno$errstr30);
    if (!
    $fp) {
        echo 
    "Down!<br>\n";
    } else {
        echo 
    "Up!<br>\n";
    }
    ?>
    It's basicly taken off of php.net's manual, about fsockopen() command.


Bookmarks

Posting Permissions

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