title: Php laravel memory limit error
body: <p>I am making currently migration from one database to another, project is on laravel so I am creating laravel command for this. I have one table with about 700000 records. I have created function with LIMIT and transactions to optimize query but still getting out of memory error from PHP. 
  Here is my code:</p>
  
  <pre><code>ini_set('memory_limit', '750M');  // at beginning of file
  
  $circuit_c = DB::connection('legacy')-&gt;select('SELECT COUNT(*) FROM tbl_info');
  $count = (array) $circuit_c[0];
  $counc = $count['COUNT(*)'];
  $max =  1000;
  $pages = ceil($counc / $max);
  
      for ($i = 1; $i &lt; ($pages + 1); $i++) {
          $offset = (($i - 1) * $max);
          $start = ($offset == 0 ? 0 : ($offset + 1));
          $infos = DB::connection('legacy')-&gt;select('SELECT * from tbl_info LIMIT ' . $offset . ', ' . $max);
          DB::connection('mysql')-&gt;transaction(function() use ($infos) {
              foreach ($infos as $info) {
                  $validator = Validator::make($data = (array) $info, Info::$rules);
                  if ($validator-&gt;passes()) {
                      if ($info-&gt;record_type == 'C') {
                          $b_user_new = Info::create($data);
                          unset($b_user_new);
  
                      }
                  }
                  unset($info);
                  unset($validator);
              }
          });
          unset($infos);
      }
  </code></pre>
  
  <p>Error is this:</p>
  
  <pre><code>user@lenovo /var/www/info $ php artisan migratedata
  PHP Fatal error:  Allowed memory size of 786432000 bytes exhausted (tried to allocate 32 bytes) in /var/www/info/vendor/laravel/framework/src/Illuminate/Database/Grammar.php on line 75
  </code></pre>
  
  <p>Error is show after importing about 50000 records.</p>