title: How to convert XML to CSV efficiently
body: <p>I’m testing my PHP code that converts XML to CSV .</p>
  
  <p>I take from XML from a web site as the HTTP response by using  <code>HTTP_Request().</code></p>
  
  <p>However I need more than 15GB memory although XML size is 500MB. </p>
  
  <p>I checked memory consumption each steps of processing XML to CSV like bellow.</p>
  
  <p><code>sendRequest()</code> 1.5MB to 500MB   &lt;- data size of HTTP response is about 500MB too</p>
  
  <p><code>$res = getResponceBody()</code> 1.0GB   </p>
  
  <p><code>$xmlstr = mv_convert_encoding($res)</code>  1.7GB</p>
  
  <p><code>$xml = sinplexml_load_string($xmlstr)</code> 600MB</p>
  
  <p><code>$json = json_encode($xml)</code>  1MB to 6.5GB</p>
  
  <p><code>$arry = json_decode($json, true)</code> 10.0GB</p>
  
  <p><code>Create CSV from $array</code> 4.5GB  </p>
  
  <p>I want know how to reduce memory consumption.</p>
  
  <p>Are there some steps I can short cut for converting XML to CSV?</p>
  
  <p>Especially <code>json_encode</code> and <code>json_decode</code> I’m not sure how they work but
  If I can cut them I can reduce 90% of memory consumption.</p>