我試圖將〜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
有關的錯誤。Laravel DB插入錯誤:允許的內存大小用盡
這裏是我的代碼(試圖用兩個口才流利):
<?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";
}
}
}
我正好碰到這個問題,增加內存限制是速戰速決。更好的解決方案是關閉查詢日誌記錄,如@Erik所建議的,低於 – th3hamburgler