Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8537001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:47:43+00:00 2026-06-11T10:47:43+00:00

I have sockets querying a game server on a few pages in my application.

  • 0

I have sockets querying a game server on a few pages in my application. I have an issue that when i navigate too quickly between the pages, the socket has no closed properly and the error i get is this;

socket_recv() [function.socket-recv]: unable to read from socket [104]: Connection reset by peer

I have to wait around 4-5 seconds after each page has fully loaded, for it to close.

Here is the code for the socket;

function QueryMinecraft( $IP, $Port, $Timeout =1 )
{
    $Socket = Socket_Create( AF_INET, SOCK_STREAM, SOL_TCP );

    Socket_Set_Option( $Socket, SOL_SOCKET, SO_SNDTIMEO, array( 'sec' => (int)$Timeout, 'usec' => 0 ) );

    if( $Socket === FALSE || @Socket_Connect( $Socket, $IP, (int)$Port ) === FALSE )
    {
        Socket_Close( $Socket );
        return FALSE;
    } else {
        Socket_Close( $Socket );
        return TRUE;
    }      
    Socket_Close( $Socket );                  
}   

And here is the code for the socket on the other page;

function QueryMinecraft( $IP, $Port, $Timeout = 3 )
{
    $Socket = Socket_Create( AF_INET, SOCK_STREAM, SOL_TCP );

    Socket_Set_Option( $Socket, SOL_SOCKET, SO_SNDTIMEO, array( 'sec' => (int)$Timeout, 'usec' => 0 ) );

    if( $Socket === FALSE || @Socket_Connect( $Socket, $IP, (int)$Port ) === FALSE )
    {
        return FALSE;
    }

    Socket_Send( $Socket, "\xFE", 1, 0 );
    $Len = Socket_Recv( $Socket, $Data,256, 0 );


    if( $Len < 4 || $Data[ 0 ] != "\xFF" )
    {
        return FALSE;
    }

    $Data = SubStr( $Data, 3 );
    $Data = iconv( 'UTF-16BE', 'UTF-8', $Data );
    $Data = Explode( "\xA7", $Data );

    return Array(
        'HostName'   => SubStr( $Data[ 0 ], 0, -1 ),
        'Players'    => isset( $Data[ 1 ] ) ? IntVal( $Data[ 1 ] ) : 0,
        'MaxPlayers' => isset( $Data[ 2 ] ) ? IntVal( $Data[ 2 ] ) : 0
    );
}

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:47:44+00:00Added an answer on June 11, 2026 at 10:47 am

    Woohoo, specific knowledge I know a lot about! There should be a minecraft tag.

    I believe this is actually a minecraft server limitation, as opposed to a problem with your php code. You may notice that if you are using the minecraft client and you visit the multiplayer page several times quickly, you will experience the same issue (connections to servers to query player count and MOTD will be denied). It resolves itself if you wait 5 or 6 seconds between visits.

    Your solution might therefore be to cache the response from servers for 10 seconds or 30 seconds or so, so that the server doesn’t deny them.

    I don’t know if you have a local SQL database you can use, but you should be able to set yourself up a table containing the server ip (not the hostname, which is not guaranteed to be unique. The IP isn’t either but its a better bet), the MOTD, the current and max players, and a last-checked timestamp. You can simply do your database query, check the timestamp to make sure the cached value hasnt expired, and if it has, query the server directly and store the result in the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server-client application [TCP sockets, .NET 4.0].. the application about : do
I have a socket.io server listening for certain events on sockets. Whenever an event
I have a python server that listens on a couple sockets. At startup, I
We have a program that uses QoS-sockets, our softphone application uses QoS for the
In my program I have several sockets on the server. Each socket has its
I have a client-server program that uses sockets to transfer information in a stateful
I have an application using sockets.. a client and server program like mySql.. I
I have a small utility application that handles sockets, both TCP and UDP. Occasionally,
I'm implementing an application that will have a lot of clients querying lots of
Sockets on Linux question I have a worker thread that is blocked on an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.