php - fsockopen

Discussion in 'OT Technology' started by ziggie216, Jul 24, 2003.

  1. ziggie216

    ziggie216 New Member

    Joined:
    Jun 6, 2001
    Messages:
    29,850
    Likes Received:
    0
    Location:
    San Francisco
    <?
    if($fp = fsockopen ("209.220.161.56", 27015, $errno, $errstr, 10)){
    echo "server in online";
    }else{
    echo "server is offline";
    ?>

    i'm trying to check if the server is online or not, but some how the script isnt working correctly. I know the server is working, pingable, but some how this script detect is as offline. Does anyone know why?
     
  2. Jericho

    Jericho Active Member

    Joined:
    Oct 21, 2002
    Messages:
    34,140
    Likes Received:
    0
    hmm I don't know PHP but I think you might want to review your if statement, why are you assigning the fsockopen to the fp variable, can't you just go:

    Code:
    <?
    if(fsockopen ("209.220.161.56", 27015, $errno, $errstr, 10)){
    echo "server in online";
    }else{
    echo "server is offline";
    ?>
    
     
  3. skinjob

    skinjob Active Member

    Joined:
    Jan 6, 2001
    Messages:
    2,337
    Likes Received:
    0
    Location:
    Aztlán
    you're trying to connect to port 27015. are you certain something is listening on that port?
     
  4. ziggie216

    ziggie216 New Member

    Joined:
    Jun 6, 2001
    Messages:
    29,850
    Likes Received:
    0
    Location:
    San Francisco
    27015 is a counter-strike server port.
     
  5. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Try changing 27015 to a known port that is listening (say port 80 maybe?). Then run the script again. Does it work? If not, then you definitely have a PHP problem (fsocks enabled in PHP?). If it does work, but you know the server is running and port 27015 is up, then it may be a router issue.
     
  6. Astro

    Astro Code Monkey

    Joined:
    Mar 18, 2000
    Messages:
    2,047
    Likes Received:
    0
    Location:
    Cleveland Ohio
    Technicality: You're missing a closing '}' after the else group. Not sure if your PHP file has it or not, but that might be something to look at.

    Should be:

    PHP:
    <?
    if(
    $fp fsockopen ("209.220.161.56"27015$errno$errstr10)){
    echo 
    "server in online";
    }else{
    echo 
    "server is offline";
    }
    ?>
    Just a coding opinion, but wouldn't you say this might be a little easier to read/troubleshoot:

    PHP:
    if($fp fsockopen ("209.220.161.56"27015$errno$errstr10))
        {
        echo 
    "server in online";
        }  
    // end if($fp = fsockopen ("209.220.161.56", 27015, $errno, $errstr, 10))
    else
        {
        echo 
    "server is offline";
        }  
    // end else
    Or

    PHP:
    if($fp fsockopen ("209.220.161.56"27015$errno$errstr10))
        echo 
    "server in online";
    else
        echo 
    "server is offline";
     
  7. crotchfruit

    crotchfruit Guest

    why don't you print out $errno and $errstr. i'll bet those tell you what the problem is :eek3:
     

Share This Page