title: Google Big Query + PHP -> How to fetch a large data set without running out of memory
body: <p>I am trying to run a query in BigQuery/PHP (using google php SDK) that returns a large dataset (can be 100,000 - 10,000,000 rows).</p>
  
  <pre><code>$bigqueryService = new Google_BigqueryService($client);
  
  $query = new Google_QueryRequest();
  $query-&gt;setQuery(...);
  
  $jobs = $bigqueryService-&gt;jobs;
  $response = $jobs-&gt;query($project_id, $query); 
  //query is a syncronous function that returns a full dataset
  </code></pre>
  
  <p>The next step is to allow the user to download the result as a CSV file.</p>
  
  <p>The code above will fail when the dataset becomes too large (memory limit).
  What are my options to perform this operation with lower memory usage ?</p>
  
  <p>(I figured an option is to save the results to another table with BigQuery and then start doing partial fetch with LIMIT and OFFSET but I figured a better solution might be available..)</p>
  
  <p>Thanks for the help</p>