set_time_limit(0);
try {
//上传文件位置,这里默认是在storage中,如有修改请对应替换
$file = storage_path('/app/public/' . $input['file']);
$domain = [];
foreach($this->readTxt($file) as $key=>$line) {
$domain[$key] = $line;
}
//数组分块处理
$chunck = collect($domain);
$chunks = $chunck->chunk(1000);
$chunks->all();
foreach ($chunks as $key=>$val){
$arr = [];
foreach ($val as $k =>$value){
$arr[$k]['domain'] = $value;
$arr[$k]['created_at'] = date('Y-m-d H:i:s');
}
DB::table('domain')->insert($arr);
}
}catch (\Exception $e) {
return $this->response()->error($e->getMessage());
}
参考文章:https://learnku.com/articles/62505
网友评论