title: Get multiple pages with a single fsockopen
body: <p>Hy all.
  I need to get the content of multiple pages from a single domain.
  Now for each page I use an fsockopen connection, and I get the content of the page this way:</p>
  
  <pre><code>&lt;?php
  $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
  if (!$fp) {
      echo "$errstr ($errno)&lt;br /&gt;\n";
  } else {
      $out = "GET /page1.html HTTP/1.1\r\n";
      $out .= "Host: www.example.com\r\n";
      $out .= "Connection: Close\r\n\r\n";
      fwrite($fp, $out);
      while (!feof($fp)) {
          fgets($fp, 128);
      }
      fclose($fp);
  }
  </code></pre>
  
  <p>?></p>
  
  <p>My script wastes time, with reconnecting to the domain, to get the second page.
  I was wondering, if is possible to use a single connection, and to get multiple pages, like this:</p>
  
  <pre><code>&lt;?php
  $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30);
  if (!$fp) {
      echo "$errstr ($errno)&lt;br /&gt;\n";
  } else {
  
      $out = "GET /page1.html HTTP/1.1\r\n";
      $out .= "Host: www.example.com\r\n";
      $out .= "Connection: Close\r\n\r\n";
      fwrite($fp, $out);
      while (!feof($fp)) {
          fgets($fp, 128);
      } $out = "GET /page2.html HTTP/1.1\r\n";
      $out .= "Host: www.example.com\r\n";
      $out .= "Connection: Close\r\n\r\n";
      fwrite($fp, $out);
      while (!feof($fp)) {
          fgets($fp, 128);
      }
      fclose($fp);
  }
  </code></pre>
  
  <p>?></p>
  
  <p>But this method is returning the page1.html two times, I don't know why.</p>
  
  <p>I tried to use: Connection: keep alive, or HTTP/1.0, but in this cases I didn't get anything from the server (infinite executing time of my script).</p>
  
  <p>Any suggestion to solve this?</p>
  
  <p>Thank you!</p>