Laravel DB插入错误:允许的内存大小已用尽 [英] Laravel DB Insert Error: Allowed Memory Size Exhausted
问题描述
尝试在数据库中插入约2万条记录时遇到问题.我注意到,即使我在foreach循环中回显,也没有在命令行中输出任何内容.相反,插入与...有关的〜9440条记录后出现错误.
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 in the command line. Instead, I get an error after inserting ~9440 records relating to...
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
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进行了尝试):
Here is my code (tried using both Eloquent and 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 $total\n";
}
}
}
推荐答案
此错误表示您的PHP脚本由于为脚本分配的内存不足而耗尽了内存限制.
This error depicts that your PHP script has exhausted memory limit due to insufficient memory allocated for script.
您需要使用ini_set函数来增加memory_limit 例如ini_set('memory_limit','128M');
You need to increase memory_limit using the ini_set function e.g ini_set('memory_limit','128M');
这篇关于Laravel DB插入错误:允许的内存大小已用尽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!