title: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 80 bytes) while fetching json data from server in php
body: <p>I am trying to fetch the huge data from server around 500000 rows from database in json format, and getting memory exhausted error. Every thing works fine when I tries with 100 rows, but i need to fetch the 500000 rows in a one go. I am using postman extension to fetch this data. Guys I am not the champ of database but i tried a whole day and found some useful hint <a href="https://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte">this</a> <a href="https://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml">this</a> <a href="https://stackoverflow.com/questions/25220608/joomla-allowed-memory-size-of-1073741824-bytes-exhausted">this</a> and many more but no luck.</p>
  
  <p>I know this is not a good solution but I also tried this <code>ini_set('memory_limit', '-1');</code></p>
  
  <p><strong>This is what I am doing :</strong>  </p>
  
  <pre><code> $response["data"] = array();
  
          $result = $db-&gt;getData();
          while ($data= $result-&gt;fetch_assoc()) {
           array_push($response["data"], $data);
               }
  
            file_put_contents('newData.json', json_encode($response,128));
          echoRespnse(200, $response);
  </code></pre>
  
  <p>I have given my 1 day and tried almost 100's of solution but no luck, I also know this is posted many times, but I thinks my problem is a bit different. Please give your valuable suggestion, every suggestion will be appreciated.</p>