title: PHP fsockopen loses connection
body: <p>I need to retrieve quite a lot of remote data using soap requests (retrieving about 12000 delivery-orders, and make a request for each separate order). On my test server (windows with Xampp) it works fine, and takes about an hour or so. Putting the scripts on the production server (Linux), the connection gets lost after about 10 minutes (it  varies).</p>
  
  <p>I tried changing the header from "Connection: Close" to "Connection: Keep-Alive", but that makes retrieving each record so slow for some reason - like 3 records instead of 170 records per minutes. Note sure if it is because of the fputs or the fgets-loop.</p>
  
  <p>Can anybody tell me how to force the connection to be alive for a given period?</p>
  
  <p>Basically my script is:</p>
  
  <pre><code>if (!is_resource($fp))
  {
      $fp = @fsockopen($host, $port, $errno, $errstr);
      if (!$fp) { echo "soap_parser error message is: $errstr ($errno)&lt;br /&gt;\n";exit;}
      stream_set_timeout($fp,3600);//one hour
  }
  
  $soap_out  = "POST " . $path . " HTTP/1.1\r\n";
  $soap_out .= "Host: " . $hostname . "\r\n";
  $soap_out .= "User-Agent: MYSOAPREQUEST \r\n";
  $soap_out .= "Content-Type: text/xml;charset=UTF-8;\r\n";
  $soap_out .= "Content-Length: ".strlen($xml_request)."\r\n";
  $soap_out .= "Connection: Close\r\n"; 
  $soap_out .= "Cache-Control: no-cache\r\n";
  $soap_out .= "SOAPAction: ".$soap_action."\r\n\r\n"; 
  $soap_out .= $xml_request;
  
  fputs($fp, $soap_out); //send request SOAP
  $soap_in = "";
  
  while (!feof($fp)) 
  {
         $soap_in .= fgets($this-&gt;fp, 512);
  }
  
  return $soap_in;
  </code></pre>