Laravel DB Insert Error: Allowed Memory Size Exhausted

前端 未结 2 1170
广开言路
广开言路 2021-01-05 16:48

I\'m running into an issue when trying to insert ~20K records into my DB. I notice that even though I\'m echoing inside my foreach loop, I\'m not getting anything outputted

相关标签:
2条回答
  • 2021-01-05 17:16

    The accepted answer is fixing the symptom rather then the problem. The problem is the Laravel query log (in memory) is eating all your RAM when you execute such a large # of queries. See the answer here: https://stackoverflow.com/a/18776710/221745

    Or, in brief, turn off query logging via:

    DB::disableQueryLog()
    

    Before executing 20k queries

    0 讨论(0)
  • 2021-01-05 17:39

    This error depicts that your PHP script has exhausted memory limit due to insufficient memory allocated for script.

    You need to increase memory_limit using the ini_set function e.g ini_set('memory_limit','128M');

    0 讨论(0)
提交回复
热议问题