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

  • Home
  • SEARCH
  • 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 7763553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:41:18+00:00 2026-06-01T14:41:18+00:00

I am sending and receiving data using fsockopen and fwrite. My application receives the

  • 0

I am sending and receiving data using fsockopen and fwrite. My application receives the proper response, but seems to wait until some sort of timeout before continuing. I suspect that I am not closing the connection properly after it finishes receiving the response, which explains the wait. Could someone take a look at my code?

private static function Send($URL, $Data) {
            $server = parse_url($URL, PHP_URL_HOST);
            $port = parse_url($URL, PHP_URL_PORT);

            // If the parsing the port information fails, we will assume it's on a default port.
            // As such, we'll set the port in the switch below.
            if($port == null) {
                switch(parse_url($URL, PHP_URL_SCHEME)) {
                    case "HTTP":
                        $port = 80;
                        break;
                    case "HTTPS":
                        $port = 443;
                        break;

                }
            }

            // Check if we are using a proxy (debug configuration typically).
            if(\HTTP\HTTPRequests::ProxyEnabled) {
                $server = \HTTP\HTTPRequests::ProxyServer;
                $port = \HTTP\HTTPRequests::ProxyPort;
            }

            // Open a connection to the server.
            $connection = fsockopen($server, $port, $errno, $errstr);
            if (!$connection) {
                die("OMG Ponies!");
            }

            fwrite($connection, $Data);

            $response = "";
            while (!feof($connection)) {
                $response .= fgets($connection);
            }
            fclose($connection);

            return $response;
        }
  • 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-01T14:41:19+00:00Added an answer on June 1, 2026 at 2:41 pm

    The problem is with this line:

    while (!feof($connection)) {
    

    Sockets are streams; unless the other side closes the connection first, feof will never return true and your script will eventually time out.

    To perform an orderly shutdown both parties have to close their end of the connection; one of them can do it as a response to the other, but clearly if both are waiting for the other to close first then noone ever will.

    Does the program on the other side close the connection after outputting something? It seems not.

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

Sidebar

Related Questions

I got success in sending/receiving data using TCP Sockets over LAN but I want
I'm using an AsyncTask to establish a TCP Connection and sending/receiving data through it.
I'm sending a string of data via CURL using data from post, and receiving
I am using the same UDP socket for sending and receiving data. I am
I am sending data using the HTTP POST verb . But I am not
I am sending HTTP GET request and receiving data here: ssize_t numBytes = recvfrom(sock,
I am using a script that is sending out emails and I am receiving
sending mail along with embedded image using asp.net I have already used following but
I am using CFMessagePortRef for inter process communication. for receiving data , i have
I'm trying to make motion controller using the values from android sensors. Currently sending/receiving

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.