title: fsockopen & Close connection in PHP but keep executing script
body: <p>I've a PHP script that need Close connection after return data, but continue executing:</p>
  
  <pre><code>&lt;?php
    // Some code
  
    ob_start();
  
    echo $data;
  
    header("Content-type: application/soap+xml;charset=UTF-8\r\n");
    header("Content-Length: " . ob_get_length() . "\r\n");
    header("Content-Encoding: none\r\n");
    header("Connection: close\r\n\r\n");
  
    // Print buffer
    ob_end_flush();
    ob_flush();
    flush();
  
    // Close connection
  
    // Some code, continue executing
  ?&gt;
  </code></pre>
  
  <p>It's work with some clients, but I need to call sometimes with an other PHP script</p>
  
  <pre><code>&lt;?php
      // Some code
  
      $connection = @fsockopen($url['host'], $url['port'], $errno, $errstr);
  
      if (!$connection) { 
        throw new Exception('');
      }
  
      fputs($connection, "POST {$url['path']} HTTP/1.1\r\n");
      fputs($connection, "Host: {$url['host']}\r\n");
      fputs($connection, "Content-type: text/xml;charset=UTF-8\r\n");
      fputs($connection, "SOAPAction: \"{$soapaction}\"\r\n");
      fputs($connection, "Content-Length: " . strlen($request) . "\r\n");
      fputs($connection, "Content-Encoding: none\r\n");
      fputs($connection, "Connection: close\r\n\r\n");
      fputs($connection, $request);
  
      $respponse = '';
      while(!feof($connection)) {
        // receive the results of the request
        $response .= fgets($connection, 512);
      }
  
      // some code
  ?&gt;
  </code></pre>
  
  <p>The problem is: fsockopen doesn't close connection when receive the data, only when all first scripts ends.</p>
  
  <p>The only idea I have, it is check the length and close manual when the data is received.</p>