Results 1 to 2 of 2

Thread: Sending server commands

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    129

    Sending server commands

    Hello all;
    i am trying to make a little server stat signiture. currently i am trying to get the info from my server using php (obviously i have never done) now i started my little game server and ran WPE PRO on it, it showe that when it receives the command:
    Code:
    ../status.
    it sends the server stats. my question is that how might one implement this in php?
    so far i have this: (i do not know if i am on the right track.)

    Code:
    
    <?php
    
    $handle = fsockopen('192.168.1.2', 3558, $erno, $errstr, 15);
    if (!$handle) {
      //if connection fails exit and tell us what went wrong.
      die("Connect failed:its all your falut!!!! jerk! $errstr\n");
    }
    else {
      $message = "../whatmap.\n";
      //read the first responds the server gives us (usually the version string)
    
    
      //send our data to the game server
      
      
      
      fwrite($handle, "$message");
    $responses = fgets($handle, 20);
      /*
       until there is no more output to read from the smtp server keep storing all the output
       in the $responses variable. Once there's nothing else to read show us all the output
       and exit
      */
    while (!feof($handle)) {
         $responses .= fgets($handle, 20);
    }
    
      echo "$responses";
    
      fclose($handle);
    }
    ?>
    this code is from a tutorial modified by me (some what)
    this code just returns an empty page. i do not even know that i am on the right track.

    i would greatly appreciate any help at all.
    Cheak out my Movie!

    Learning c++


  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Sending server commands

    You are on the right track yes.

    There doesn't seem to be anything wrong with that code. I would suggest you read more than 20 bytes of data upon each iteration of fgets($handle, 20), for example 128 bytes.

    If your getting a blank screen, with that code it could mean there's an error in the code or the server did not send any messages back.

    If your setup is to not show errors, the white screen could indicate a fatal error such as sockets not enabled. Check your error_log file for problems.

    I would put an echo in the 'else' and make sure that it's getting to that part (at the start and end). If those show then there is no fatal error.

    If you are happy there's no problems with the script then verify the server is working as it should. Check that the port is open, check the port number. Is the server behind a router/firewall?
    Chris

Posting Permissions

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



Click Here to Expand Forum to Full Width