laravel'在基本查询上允许的内存大小为134217728字节已用尽' [英] laravel 'Allowed memory size of 134217728 bytes exhausted' on basic query

查看:85
本文介绍了laravel'在基本查询上允许的内存大小为134217728字节已用尽'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我无法执行以下操作:

I have no qlue why I can't get the following to work:

DB::table('twitter_hashtags')->paginate(5);

每一次我得到(第二个数字往往都不同)

Every single time I get (the second number tends to differs)

Allowed memory size of 134217728 bytes exhausted (tried to allocate 95735352 bytes)

我尝试使用( 18776710 ),但这没什么作用

I tried using as in (18776710), but that did not make any difference

DB::connection()->disableQueryLog();

删除->paginate(5)没有任何区别.

当我尝试时:

DB::select('SELECT * FROM twitter_hashtags');

它工作正常,但是我不能在分页选项中使用该版本.

It works fine, but then I can't use the build in the pagination option.

有人建议吗?

表twitter_hashtags当前具有5500条记录. id,tweet_id和主题标签已保存,因此表太大不会成为问题.

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.

桌子的大小:

Data    384,0   KB
Index   464,0   KB
Total   848,0   KB

更新

根据要求提供更多信息

这是动作

public function getHashtags()
{           
    DB::connection()->disableQueryLog(); // With or without does not make a difference
    $retweets = DB::table('twitter_hashtags')->paginate(10);        

    // Show the page
    return View::make('twitter/retweets', compact('retweets'));

}

如您所见,我使用转发视图,问题也存在于转发中,或者我尝试以此方式获取数据的几乎任何其他表中也存在.

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.

视图"

</pre><? print_r($retweets) ?></pre>

我用来创建表的迁移

public function up()
{
    Schema::create('twitter_hashtags', function($table)
    {
        // Basic run information
        $table->increments('id');
        $table->string('status_id')->index();
        $table->string('hashtag')->index();

        // Misc.
        $table->timestamps();
    });
}

这些是将内存限制提高到256M时响应的前100行左右

These are the first 100 or so lines of the response when raised the memory limit to 256M

Illuminate\Database\Query\Builder Object
(
    [connection:protected] => Illuminate\Database\MySqlConnection Object
        (
            [pdo:protected] => PDO Object
                (
                )

            [queryGrammar:protected] => Illuminate\Database\Query\Grammars\MySqlGrammar Object
                (
                    [wrapper:protected] => `%s`
                    [selectComponents:protected] => Array
                        (
                            [0] => aggregate
                            [1] => columns
                            [2] => from
                            [3] => joins
                            [4] => wheres
                            [5] => groups
                            [6] => havings
                            [7] => orders
                            [8] => limit
                            [9] => offset
                            [10] => unions
                        )

                    [tablePrefix:protected] => 
                )

            [schemaGrammar:protected] => 
            [postProcessor:protected] => Illuminate\Database\Query\Processors\Processor Object
                (
                )

            [events:protected] => Illuminate\Events\Dispatcher Object
                (
                    [container:protected] => Illuminate\Foundation\Application Object
                        (
                            [booted:protected] => 1
                            [bootingCallbacks:protected] => Array
                                (
                                    [0] => Closure Object
                                        (
                                            [parameter] => Array
                                                (
                                                    [$app] => 
                                                )

                                        )

                                    [1] => Closure Object
                                        (
                                            [static] => Array
                                                (
                                                    [instance] => Illuminate\Log\LogServiceProvider Object
                                                        (
                                                            [defer:protected] => 1
                                                            [app:protected] => Illuminate\Foundation\Application Object
 *RECURSION*
                                                        )

                                                )

                                        )

                                    [2] => Closure Object
                                        (
                                            [static] => Array
                                                (
                                                    [instance] => Illuminate\Mail\MailServiceProvider Object
                                                        (
                                                            [defer:protected] => 1
                                                            [app:protected] => Illuminate\Foundation\Application Object
 *RECURSION*
                                                        )

                                                )

                                        )

                                    [3] => Closure Object
                                        (
                                            [static] => Array
                                                (
                                                    [instance] => Illuminate\Queue\QueueServiceProvider Object
                                                        (
                                                            [defer:protected] => 1
                                                            [app:protected] => Illuminate\Foundation\Application Object
 *RECURSION*
                                                        )

                                                )

                                        )

                                    [4] => Closure Object
                                        (
                                            [static] => Array
                                                (
                                                    [instance] => Illuminate\Translation\TranslationServiceProvider Object
                                                        (
                                                            [defer:protected] => 1
                                                            [app:protected] => Illuminate\Foundation\Application Object
 *RECURSION*
                                                        )

                                                )

                                        )

更新2

根据要求.这是响应:

Array
(
    [total] => 5689
    [per_page] => 5
    [current_page] => 1
    [last_page] => 1138
    [from] => 1
    [to] => 5
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 1
                    [status_id] => 384992474579484672
                    [hashtag] => Twenterand
                    [created_at] => 2013-10-01 11:00:02
                    [updated_at] => 2013-10-01 11:00:02
                )

            [1] => stdClass Object
                (
                    [id] => 2
                    [status_id] => 384992323190280192
                    [hashtag] => Twenterand
                    [created_at] => 2013-10-01 11:00:03
                    [updated_at] => 2013-10-01 11:00:03
                )

            [2] => stdClass Object
                (
                    [id] => 3
                    [status_id] => 384989174014545921
                    [hashtag] => PVDA
                    [created_at] => 2013-10-01 11:00:03
                    [updated_at] => 2013-10-01 11:00:03
                )

            [3] => stdClass Object
                (
                    [id] => 4
                    [status_id] => 384988499188801536
                    [hashtag] => GR2014
                    [created_at] => 2013-10-01 11:00:03
                    [updated_at] => 2013-10-01 11:00:03
                )

            [4] => stdClass Object
                (
                    [id] => 5
                    [status_id] => 384986184092356608
                    [hashtag] => GR2014
                    [created_at] => 2013-10-01 11:00:03
                    [updated_at] => 2013-10-01 11:00:03
                )

        )

)
                                )

                                        )

更新3

这是我用于getStatuses的代码

Here the code I use for the getStatuses

public function getStatuses()
{           
    // Get all the paginated statuses
    $statuses = DB::table('twitter_statuses')
            ->select('status_id', 'text', 'user_screen_name','datetime','place')
            ->orderBy('datetime', 'DESC')
            ->paginate(10);

    // Show the page
    return View::make('twitter/statuses', compact('statuses'));
}

以及完整的查看文件

@extends('layouts/default')

{{-- Page title --}}
@section('title')
Twitter Statuses ::
@parent
@stop

{{-- Page content --}}
@section('content')
<h1>Twitter Statuses</h1>
<div class="container">
    <table class="table">
        <tr>
            <th>Datum</th>
            <th>Gebruiker</th>
            <th>Tweet</th>
            <th>Locatie</th>
        </tr>
    <?php foreach ($statuses as $status): ?>
        <tr>
            <td>{{ $status->datetime; }}</td>
            <td><?php echo $status->user_screen_name; ?></td>
            <td><?php echo $status->text; ?></td>
            <td><?php echo $status->place; ?></td>
        </tr>
    <?php endforeach; ?>
    </table>
    <?php echo $statuses->links(); ?>
</div>
@stop

推荐答案

我只是遇到了同样的问题.解决方案很简单:只需在查询末尾添加->get();:

I just had the same issue. Solution is simple: Just add ->get(); at the end of the query:

public function getStatuses()
{           
    // Get all the paginated statuses
    $statuses = DB::table('twitter_statuses')
            ->select('status_id', 'text', 'user_screen_name','datetime','place')
            ->orderBy('datetime', 'DESC')
            ->paginate(10)
            ->get() 
;

    // Show the page
    return View::make('twitter/statuses', compact('statuses'));
}

这篇关于laravel'在基本查询上允许的内存大小为134217728字节已用尽'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆