title: laravel 'Allowed memory size of 134217728 bytes exhausted' on basic query
body: <p>I have no qlue why I can't get the following to work:</p>
  
  <pre><code>DB::table('twitter_hashtags')-&gt;paginate(5);
  </code></pre>
  
  <p>Every single time I get (the second number tends to differs)</p>
  
  <pre><code>Allowed memory size of 134217728 bytes exhausted (tried to allocate 95735352 bytes)
  </code></pre>
  
  <p>I tried using as in (<a href="https://stackoverflow.com/questions/18775510/laravel-eloquent-memory-leak-retrieving-the-same-record-repeatedly/18776710#18776710">18776710</a>), but that did not make any difference</p>
  
  <pre><code>DB::connection()-&gt;disableQueryLog();
  </code></pre>
  
  <p>Removing <code>-&gt;paginate(5)</code> does not make any difference. </p>
  
  <p>When I try:</p>
  
  <pre><code>DB::select('SELECT * FROM twitter_hashtags');
  </code></pre>
  
  <p>It works fine, but then I can't use the build in the pagination option.</p>
  
  <p>Anyone a suggestion?</p>
  
  <p>The table twitter_hashtags has currently 5500 records. An id, tweet_id and the hashtag are saved, so it can't be the problem that the table is too big.</p>
  
  <p>The table's size:</p>
  
  <pre><code>Data    384,0   KB
  Index   464,0   KB
  Total   848,0   KB
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>As requested some more information</p>
  
  <p>This is the action</p>
  
  <pre><code>public function getHashtags()
  {           
      DB::connection()-&gt;disableQueryLog(); // With or without does not make a difference
      $retweets = DB::table('twitter_hashtags')-&gt;paginate(10);        
  
      // Show the page
      return View::make('twitter/retweets', compact('retweets'));
  
  }
  </code></pre>
  
  <p>As you see, I use the view of retweets, the problem exits also in retweets, or nearly any other table I try to grab the data from this way.</p>
  
  <p>The 'view'</p>
  
  <p><code>&lt;/pre&gt;&lt;? print_r($retweets) ?&gt;&lt;/pre&gt;</code></p>
  
  <p>The migration I used to create the table</p>
  
  <pre><code>public function up()
  {
      Schema::create('twitter_hashtags', function($table)
      {
          // Basic run information
          $table-&gt;increments('id');
          $table-&gt;string('status_id')-&gt;index();
          $table-&gt;string('hashtag')-&gt;index();
  
          // Misc.
          $table-&gt;timestamps();
      });
  }
  </code></pre>
  
  <p>These are the first 100 or so lines of the response when raised the memory limit to 256M</p>
  
  <pre><code>Illuminate\Database\Query\Builder Object
  (
      [connection:protected] =&gt; Illuminate\Database\MySqlConnection Object
          (
              [pdo:protected] =&gt; PDO Object
                  (
                  )
  
              [queryGrammar:protected] =&gt; Illuminate\Database\Query\Grammars\MySqlGrammar Object
                  (
                      [wrapper:protected] =&gt; `%s`
                      [selectComponents:protected] =&gt; Array
                          (
                              [0] =&gt; aggregate
                              [1] =&gt; columns
                              [2] =&gt; from
                              [3] =&gt; joins
                              [4] =&gt; wheres
                              [5] =&gt; groups
                              [6] =&gt; havings
                              [7] =&gt; orders
                              [8] =&gt; limit
                              [9] =&gt; offset
                              [10] =&gt; unions
                          )
  
                      [tablePrefix:protected] =&gt; 
                  )
  
              [schemaGrammar:protected] =&gt; 
              [postProcessor:protected] =&gt; Illuminate\Database\Query\Processors\Processor Object
                  (
                  )
  
              [events:protected] =&gt; Illuminate\Events\Dispatcher Object
                  (
                      [container:protected] =&gt; Illuminate\Foundation\Application Object
                          (
                              [booted:protected] =&gt; 1
                              [bootingCallbacks:protected] =&gt; Array
                                  (
                                      [0] =&gt; Closure Object
                                          (
                                              [parameter] =&gt; Array
                                                  (
                                                      [$app] =&gt; 
                                                  )
  
                                          )
  
                                      [1] =&gt; Closure Object
                                          (
                                              [static] =&gt; Array
                                                  (
                                                      [instance] =&gt; Illuminate\Log\LogServiceProvider Object
                                                          (
                                                              [defer:protected] =&gt; 1
                                                              [app:protected] =&gt; Illuminate\Foundation\Application Object
   *RECURSION*
                                                          )
  
                                                  )
  
                                          )
  
                                      [2] =&gt; Closure Object
                                          (
                                              [static] =&gt; Array
                                                  (
                                                      [instance] =&gt; Illuminate\Mail\MailServiceProvider Object
                                                          (
                                                              [defer:protected] =&gt; 1
                                                              [app:protected] =&gt; Illuminate\Foundation\Application Object
   *RECURSION*
                                                          )
  
                                                  )
  
                                          )
  
                                      [3] =&gt; Closure Object
                                          (
                                              [static] =&gt; Array
                                                  (
                                                      [instance] =&gt; Illuminate\Queue\QueueServiceProvider Object
                                                          (
                                                              [defer:protected] =&gt; 1
                                                              [app:protected] =&gt; Illuminate\Foundation\Application Object
   *RECURSION*
                                                          )
  
                                                  )
  
                                          )
  
                                      [4] =&gt; Closure Object
                                          (
                                              [static] =&gt; Array
                                                  (
                                                      [instance] =&gt; Illuminate\Translation\TranslationServiceProvider Object
                                                          (
                                                              [defer:protected] =&gt; 1
                                                              [app:protected] =&gt; Illuminate\Foundation\Application Object
   *RECURSION*
                                                          )
  
                                                  )
  
                                          )
  </code></pre>
  
  <p><strong>Update 2</strong></p>
  
  <p>As requested. This is the response:</p>
  
  <pre><code>Array
  (
      [total] =&gt; 5689
      [per_page] =&gt; 5
      [current_page] =&gt; 1
      [last_page] =&gt; 1138
      [from] =&gt; 1
      [to] =&gt; 5
      [data] =&gt; Array
          (
              [0] =&gt; stdClass Object
                  (
                      [id] =&gt; 1
                      [status_id] =&gt; 384992474579484672
                      [hashtag] =&gt; Twenterand
                      [created_at] =&gt; 2013-10-01 11:00:02
                      [updated_at] =&gt; 2013-10-01 11:00:02
                  )
  
              [1] =&gt; stdClass Object
                  (
                      [id] =&gt; 2
                      [status_id] =&gt; 384992323190280192
                      [hashtag] =&gt; Twenterand
                      [created_at] =&gt; 2013-10-01 11:00:03
                      [updated_at] =&gt; 2013-10-01 11:00:03
                  )
  
              [2] =&gt; stdClass Object
                  (
                      [id] =&gt; 3
                      [status_id] =&gt; 384989174014545921
                      [hashtag] =&gt; PVDA
                      [created_at] =&gt; 2013-10-01 11:00:03
                      [updated_at] =&gt; 2013-10-01 11:00:03
                  )
  
              [3] =&gt; stdClass Object
                  (
                      [id] =&gt; 4
                      [status_id] =&gt; 384988499188801536
                      [hashtag] =&gt; GR2014
                      [created_at] =&gt; 2013-10-01 11:00:03
                      [updated_at] =&gt; 2013-10-01 11:00:03
                  )
  
              [4] =&gt; stdClass Object
                  (
                      [id] =&gt; 5
                      [status_id] =&gt; 384986184092356608
                      [hashtag] =&gt; GR2014
                      [created_at] =&gt; 2013-10-01 11:00:03
                      [updated_at] =&gt; 2013-10-01 11:00:03
                  )
  
          )
  
  )
                                  )
  
                                          )
  </code></pre>
  
  <p><strong>Update 3</strong></p>
  
  <p>Here the code I use for the getStatuses</p>
  
  <pre><code>public function getStatuses()
  {           
      // Get all the paginated statuses
      $statuses = DB::table('twitter_statuses')
              -&gt;select('status_id', 'text', 'user_screen_name','datetime','place')
              -&gt;orderBy('datetime', 'DESC')
              -&gt;paginate(10);
  
      // Show the page
      return View::make('twitter/statuses', compact('statuses'));
  }
  </code></pre>
  
  <p>And the complete view file</p>
  
  <pre><code>@extends('layouts/default')
  
  {{-- Page title --}}
  @section('title')
  Twitter Statuses ::
  @parent
  @stop
  
  {{-- Page content --}}
  @section('content')
  &lt;h1&gt;Twitter Statuses&lt;/h1&gt;
  &lt;div class="container"&gt;
      &lt;table class="table"&gt;
          &lt;tr&gt;
              &lt;th&gt;Datum&lt;/th&gt;
              &lt;th&gt;Gebruiker&lt;/th&gt;
              &lt;th&gt;Tweet&lt;/th&gt;
              &lt;th&gt;Locatie&lt;/th&gt;
          &lt;/tr&gt;
      &lt;?php foreach ($statuses as $status): ?&gt;
          &lt;tr&gt;
              &lt;td&gt;{{ $status-&gt;datetime; }}&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $status-&gt;user_screen_name; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $status-&gt;text; ?&gt;&lt;/td&gt;
              &lt;td&gt;&lt;?php echo $status-&gt;place; ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php endforeach; ?&gt;
      &lt;/table&gt;
      &lt;?php echo $statuses-&gt;links(); ?&gt;
  &lt;/div&gt;
  @stop
  </code></pre>