加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – Laravel DB插入错误:允许的内存大小已用尽

发布时间:2020-12-14 19:44:39 所属栏目:大数据 来源:网络整理
导读:我试图在我的数据库中插入~20K记录时遇到了问题.我注意到即使我在foreach循环中回显,我也没有在命令行中输出任何内容.相反,我插入~9440有关…的记录后出错 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 91 bytes) in
我试图在我的数据库中插入~20K记录时遇到了问题.我注意到即使我在foreach循环中回显,我也没有在命令行中输出任何内容.相反,我插入~9440有关…的记录后出错

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried
to allocate 91 bytes) in
/Users/me/Sites/Laravel/database/connection.php on line 293

这是我的代码(尝试使用Eloquent和Fluent):

<?php

class Process_Controller extends Base_Controller
{
    public function action_migrate()
    {
        $properties = DB::table('raw_properties')->get('id');
        $total = count($properties);

        foreach ($properties as $x => $p) {
            $r = RawProperty::find($p->id);
            $count = $x + 1;

            $prop_details = array(
                'column' => $r->field,// Total of 21 fields
            );

            DB::table('properties')->insert($prop_details);

            echo "Created #$count of $totaln";
        }
    }
}
此错误表明由于为脚本分配的内存不足,您的PHP脚本已耗尽内存限制.

您需要使用ini_set函数增加memory_limit例如ini_set(‘memory_limit’,’128M’);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读