title: Using compression to get an external XML feed
body: <p>Using PHP, I am accessing an external URL, which is an XML feed file, and I'm parsing the results into my database. The XML file is large, around 27 MB.</p>
  
  <p>How can I compress that file before the data transfer is initiated so I receive something much smaller than 27 MB? My guess is gzip should be used, but I don't know how.</p>
  
  <p>This is my code I'm using for retreiving the data from the XML file:</p>
  
  <pre><code>$url = "http://www.website.com/feed.xml";
  $xmlStr = file_get_contents("$url") or die("can't get file");
  $xmlLinq = simplexml_load_string($xmlStr);
  </code></pre>
  
  <p>EDIT: The file is already using default gzip/deflate compression, but I seem to be accessing the non-compressed one.</p>
  
  <p>EDIT: I got this piece of code from the owner of the feed, those are supposed to be instructions how to solve this problem, but this seems to be in C#. I'd need the equivalent in PHP:</p>
  
  <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  request.Timeout = 60000;
  request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
  request.KeepAlive = false;
  request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9) Gecko/2008052906 Firefox/3.0 (.NET CLR 3.5.30729)";
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  Stream responseStream = response.GetResponseStream();
  if (response.ContentEncoding.ToLower().Contains("gzip"))
  responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
  else if (response.ContentEncoding.ToLower().Contains("deflate"))
  responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
  StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
  </code></pre>